Sunday, 14 December 2014

Permutations and Combinations of a String, A Recursion Solution

PROBLEM: 
Implement a routine that prints all possible orderings of the characters in a string. In other words, print all permutations that use all the characters from the original string. For example, given the string “hat", your function should print the strings "tha", "aht", "tah", "ath", "hta", and "hat". Treat each character in the input string as a distinct character, even if it is repeated. Given the string "aaa", your routine should print "aaa" six times. You may print the permutations in any order you choose.

SOLUTION:





vector<string>& permutate(const string& str, const PERMUTATION& kind, const string& in_probs, string form, int id)
{
       static vector<string> remuts;
       static int callingTimes = 0;
       callingTimes++;
       if (id >= str.length())
              return remuts;

       string probs = form.length() <= 0 ? str : in_probs;
       for (int x = 0; x < probs.length(); x++)
       {
              string nform = form + probs[x];
              if (nform.length() == str.length() || kind == COMBINATIONS_NO_ORDER)
              {
                     //Display new ocurance
                     remuts.push_back(nform);
                     cout << nform << endl;
              }
              if (kind == NORMAL_OCCURANCES)
              {
                     //OUTPUT: has same str length regardless of characters order, avoiding redundant of the same character in single ocurance (e.g.: "aat" of "hat" is wrong)
                     //remove Xth-char from the new prob string to get all next occurances
                     string nprobs = probs.substr(0, x) + probs.substr(x + 1, probs.length() - (x + 1));
                     if (nprobs.length() > 0 && id + 1<str.length())
                           permutate(str, kind, nprobs, nform, id + 1);//non-repeated occurances
              }
              else if (kind == COMBINATIONS_NO_ORDER)
              {
                     //OUTPUT: has deferent lengths, deferent characters orders not allowed, avoiding redundant of the same character in single ocurance (e.g.: "aat" of "hat" is wrong and "at" with "ta" is wrong)
                     //remove [0,1, .. ,Xth_char] from new prob string to prevent simillar-reordered combinations
                     string nprobs = probs.substr(x + 1, probs.length() - (x + 1));
                     if (nprobs.length() > 0 && id + 1<str.length())
                           permutate(str,kind, nprobs, nform, id + 1);//non-repeated occurances
              }else if (kind == TRUTH_TABLE)
              {
                     //OUTPUT: has same str length regardless of characters order, allow redundant of the same character in single ocurance (e.g.: "aaa" of "hat" is correct)
                     //use the same set of charaters in the new passed prob to allow output looks liks truth table.
                     permutate(str, kind, probs, nform, id + 1);//all occurances
              }
       }

       if (form.length() == 0)
              cout << "Permutations:" << remuts.size() << ", callingTimes:" << callingTimes << endl;

       return remuts;
}






Saturday, 13 December 2014

Matrix Tracing


A very clean single function to solve HackerRank's contest that has been explained in V. Anton Spraul vedio.

Problem Statement
A word from the English dictionary is taken and arranged as a matrix. e.g. "MATHEMATICS"
MATHE 
ATHEM 
THEMA 
HEMAT 
EMATI 
MATIC 
ATICS
There are many ways to trace this matrix in a way that helps you construct this word. You start tracing the matrix from the top-left position and at each iteration, you either move RIGHT or DOWN, and ultimately reach the bottom-right of the matrix. It is assured that any such tracing generates the same word. How many such tracings can be possible for a given word of length m+n-1 written as a matrix of size m * n? 

Solution:
int trace(int row, int col)
{
static int count = 0;

if (row == 1 && col == 1)
count++;
else
{
if (row <= 0 || col <= 0)
return -1;
trace(row, col - 1);
trace(row - 1, col);
}
return count;
}

Input:
  trace( 4 , 3 );

Output:
  10

Explain:
  Recursive upward traversal as shown in the next figure.



Tuesday, 17 September 2013

Web 3.0 Concepts


Understanding the New Web Era "Web 3.0"
http://readwrite.com/2009/05/13/understanding_the_new_web_era_web_30_linked_data_s#awesm=~ohCmbY4oUQFEdI

Data Sets:
They are distributed all over the world and containing all kinds of information. They Contain knowledge about a particular domain, like books, music, encyclopedic data, companies, you name it.
Also, they could re-use existing ontologies, like OpenCalai, Freebase, DBepia.


Semantic Web:
It aims to invisibly annotate web pages with a set of meta-attributes and categories to enable machines to interpret text and put it in some kind of context.
Approaches, like microformats, simplify the markup process and thus help bootstrap this problem.
As of today, Facebook has marked up all events with the hCalendar microformat including marking up their venues with hCard as well.

Liked Data:
It is the interconnection between independent data-sets, so, machine could traverse this independent web of noiseless, structured information to gather semantic knowledge of arbitrary entities and domains.

Web of Data
It is about the massive, freely accessible knowledge base, that is resulted from linked-data concept, and is forming the foundation of a new generation of applications and services.

LOD: Linking Open Data
It is a project that introduced standardiztion to link between data sets.


Real world Applications: 
* Google new features of WEB3.0:
 - Search Options
 - Rich Snippets
 - Google Squared

* DBpedia: 
 - It is a crowd-sourced community effort to extract structured information from Wikipedia and make this information available on the Web.
 - http://dbpedia.org/About

* openCalai:
 - Using a mix of natural language processing, AI techniques, and a massive databases, Reuters' solution extracts important bits of information from raw HTML pages. People, Companies, Places, and Events are really at the heart of many business articles, so being able to instantly identify them in the text is a big deal. From better search to better cross-linking and more intelligent browsing, the Calais API is an invitation to tap into one of the most powerful and pragmatic semantic platforms that exists and works today.
 - It enables publishers to connect to the Linked Data web standard that Sir Tim-Berners Lee and others in the Semantic Web community have been promoting over the past few years.
 - http://readwrite.com/2009/01/14/calais_4_linked_data#awesm=~ohGzx4dCP3hzXN
 - http://readwrite.com/2008/02/05/reuters_calais#feed=/tag/semantic-web&awesm=~ohHwSqmU1k9TJb




Thursday, 12 September 2013

Free Antivirus Software


Best Free Antivirus Software:

- avast!
- Microsoft Security Essentials
- Avira
- Malwarebytes
- AVG Anti-Virus
- Comodo
- ClamAV
- Trend Micro

Not free:

- Online Armor ++
- Sophos
- Panda
- Norton
- MacAffee
- KasperSky

Notes:

- AV_TEST: The Independent IT-Security Institute. It is an independent organization which evaluates and 

rates antivirus and security suite software.

- http://www.techsupportalert.com/best-free-anti-virus-software.htm
- The biggest win for Comodo Internet Security Complete 2013 isn't in features, but in support.
- Process Tamer:
Is a tiny (140k) and super efficient utility for Microsoft Windows XP/2K/NT/Vista/Win7 that runs in 

your system tray and constantly monitors the cpu usage of other processes. When it sees a process that is 

overloading your cpu, it reduces the priority of that process temporarily, until its cpu usage returns to a 

reasonable level.
- It is not a good idea to have more than one antivirus program running at the same time.
- If you’re even just a little bit cautious and knowledgeable about internet security, Microsoft Security 

Essentials should work just fine for you.
- Microsoft Active Protection Service is the online community that helps you choose how to respond to 

potential threats.
- Microsoft boost MSE:
* http://blogs.msdn.com/b/securitytipstalk/archive/2010/09/08/do-i-need-both-microsoft-security-

essentials-and-another-antivirus-software-program.aspx
* http://news.softpedia.com/news/Microsoft-Security-Essentials-Needs-to-Fly-Solo-155974.shtml

Monday, 18 March 2013

Cross Browser Support for inline-block Styling

Just I have a great thanks for the next two articles, they illuminate the way of bug free CSS across browsers.

Issac Schlueter
satzansatz.de



Sunday, 24 February 2013

How to set asp:CreateUserWizardas's CreateUserButton as default button of asp:Panel?



The Problem: Is to set CreateUserButton of <asp:CreateUserWizardas> as a DefaultButton of a <asp:Panel>. What to write in place of question marks of the next script? 

    <asp:Panel runat="server" ID="WizardPanel" DefaultButton="???????????????!!!!!!!!!!?">
<asp:CreateUserWizard ID="RegisterUser" runat="server" Width="449px" .......
.........................

<input type="submit" name="ctl00$ContentForm$RegisterUser$__CustomNav0$StepNextButtonButton" value="موافق" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentForm$RegisterUser$__CustomNav0$StepNextButtonButton&quot;, &quot;&quot;, true, &quot;RegisterUser&quot;, &quot;&quot;, false, false))" id="ctl00_ContentForm_RegisterUser___CustomNav0_StepNextButtonButton" class="myButton" />

</asp:CreateUserWizard>
    </asp:Panel>

[*]--------------------------------------------------------------------------------------------------
The following are some approaches that don't succeed: ... but number 4 is succeeded.
[1]--------------------------------------------------------------------------------------------------
Panel1.DefaultButton = ((Button)RegisterUserStep1.CustomNavigationTemplateContainer.FindControl("StepNextButton")).ID;
Description: 
Try to set DefaultButton programatically, but FindControl() returns nothing.
[2]--------------------------------------------------------------------------------------------------
    LookForDefaultButton(this.RegisterUser.Controls);
    protected bool LookForDefaultButton(ControlCollection collection)
    {
        foreach (Control ctrl in collection)
        {
            if (ctrl.GetType() == typeof(Button) && (ctrl as Button).ID == "StepNextButton1")
            {
                this.WizardPanel.DefaultButton = ctrl.UniqueID;
                return true;
            }
            else
                if (LookForDefaultButton(ctrl.Controls))
                    return true;

        }
        return false;
    }
Description: 
Try to set DefaultButton programatically, but <asp:Panel> issued exception of IButtonControl required.
[3]--------------------------------------------------------------------------------------------------
    <asp:Button ID="RegisterPanel" runat="server" style="display:none;" 
    ValidationGroup="RegisterUser" 
    CausesValidation="true"
    OnClientClick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentForm$RegisterUser$__CustomNav0$StepNextButtonButton&quot;, &quot;&quot;, true, &quot;RegisterUser&quot;, &quot;&quot;, false, false)); return;"
    />
Description: 
Try to Invok "WebForm_DoPostBackWithOptions" statment through a brooker button "RegisterUser", but causes a lot of problems with validation and postback.
[4]--------------------------------------------------------------------------------------------------
<div id="ctl00_ContentForm_WizardPanel" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ContentForm_RegisterUser___CustomNav0_StepNextButtonButton')">
Description:
Use <div> instead of <asp:Panel> to do the same job "Invoking WebForm_FireDefaultButton() at client" without a brooker button. All validation and postback done without any problem.

Sunday, 1 July 2012

C++ GUI Libraries


MFC is a C++ framework provided by Microsoft with its famous IDE "Visual Studio", I wish to find another GUI framework, with new look and feel. I googled the internet and found some ...

First, that is a list of all toolkits available as a GUI library: http://www.atai.org/guitool/

Second, those are a recommended set of them ....


I didn't use any of them till now but I plan to do.