Skip to main content

Posts

Showing posts from March, 2014

99 or none ... how to arrive at it programmatically?

99 Bottles to fall....how many loops to call? This simple challenge was posed as a programming question..... If there are 99 bottles on a wall and one by one they have to be removed how many loops are required? Sample code .... int number = 99 While (number > 1) { number -=1; Console.Writeline(number.ToString() + ‘ bottles are left’); } '  &nbsp The answer : No. Change to (number >=0) This will iterate through all items.

99 or none ... how to arrive at it programmatically?

99 Bottles to fall....how many loops to call? This simple challenge was posed as a programming question..... If there are 99 bottles on a wall and one by one they have to be removed how many loops are required? Sample code .... int number = 99 While (number > 1) { number -=1; Console.Writeline(number.ToString() + ‘ bottles are left’); } '  &nbsp The answer : No. Change to (number >=0) This will iterate through all items.

Debugging (mentally) does away with most woes...

Blindfold chess is supposed to be an art. Consider this problem... What letter is generated by the code below : A / X / J / S ? for (int i=1; i { for (int ii=1; ii { if (((i==ii) || ((i+ii)=6)) { Console.Writeline("*"); } else { Console.Writeline(" "); } } } Can you solve this mentally? To do so consider a 5x5 table like the one below : *       *   *   *       *       *   *   *       * Put an asterisk in the appropriate cells and you will get the pattern above. Nice ain't it?

Debugging (mentally) does away with most woes...

Blindfold chess is supposed to be an art. Consider this problem... What letter is generated by the code below : A / X / J / S ? for (int i=1; i { for (int ii=1; ii { if (((i==ii) || ((i+ii)=6)) { Console.Writeline("*"); } else { Console.Writeline(" "); } } } Can you solve this mentally? To do so consider a 5x5 table like the one below : *       *   *   *       *       *   *   *       * Put an asterisk in the appropriate cells and you will get the pattern above. Nice ain't it?

My Ex Company Outing....

My ex company Echofeel organized a one day excursion to a resort called Rishi Farms. Was awestruck by the Nature in the area.

My Ex Company Outing....

My ex company Echofeel organized a one day excursion to a resort called Rishi Farms. Was awestruck by the Nature in the area.

City Nicknames Quiz....

How much do you know about world city nicknames? Take this easy quiz to find out. Here is my result.

City Nicknames Quiz....

How much do you know about world city nicknames? Take this easy quiz to find out. Here is my result.

Be a child again....

Played the archaic game of tic tac toe @ Link Here . Results...well

Be a child again....

Played the archaic game of tic tac toe @ Link Here . Results...well

Einstein the immortal....

Please reflect on this pearl of wisdom from the holy of holies...Albert Einstein himself.

Einstein the immortal....

Please reflect on this pearl of wisdom from the holy of holies...Albert Einstein himself.

Prime or Not...check and flag

Found this problem on one of the sites. The idea is to identify a series of numbers as prime based on their ordinal and flag them accordingly based on the following conditions : a) If prime, concatenate its ordinal in the array to the output string. b) If not prime, concatenate zero. Here is the algorithm in C#. string statstring = String.Empty; bool ipr = false; double[] primetest = { 2, 65537, 2999999, 4999999, 98320414332827, 2 ^ 35 - 1, 34567875111, 12345678987654321 }; for (int i = 0; i { ipr = IsPrimeNumber(primetest[i]); if (ipr == true) { statstring += (i + 1).ToString(); } else { statstring += "0"; } } MessageBox.Show(statstring); static bool IsPrimeNumber(double num) { bool bPrime = t...

Prime or Not...check and flag

Found this problem on one of the sites. The idea is to identify a series of numbers as prime based on their ordinal and flag them accordingly based on the following conditions : a) If prime, concatenate its ordinal in the array to the output string. b) If not prime, concatenate zero. Here is the algorithm in C#. string statstring = String.Empty; bool ipr = false; double[] primetest = { 2, 65537, 2999999, 4999999, 98320414332827, 2 ^ 35 - 1, 34567875111, 12345678987654321 }; for (int i = 0; i { ipr = IsPrimeNumber(primetest[i]); if (ipr == true) { statstring += (i + 1).ToString(); } else { statstring += "0"; } } MessageBox.Show(statstring); static bool IsPrimeNumber(double num) { ...

All you can eat....new algorithm

The idea is to eat at least one of each type of food item without overspending where N is the limit.Also it is required to get the maximum satisfaction at the same time, as indicated by the respective items desirability score and find that score. Appetizer    Desirability score A ($7)    10 B ($9)    11 C ($10)    13 D ($6)    9 E ($4)    3 Main Course: R ($20)    13 S ($25)    23 T ($21)    14 U ($15)    8 V ($18)    12 Desert: I ($3)    5 J ($4)    6 K ($5)    8 L ($7)    9 M ($8)    11 Here is a generic function that does the work in C#. public void GetMaxDesirability(int N) { ArrayList ar = new ArrayList(); double sm = 0; Hashtable ht1 = new Hashtable(); Hashtable ht2 = ...

All you can eat....new algorithm

The idea is to eat at least one of each type of food item without overspending where N is the limit.Also it is required to get the maximum satisfaction at the same time, as indicated by the respective items desirability score and find that score. Appetizer    Desirability score A ($7)    10 B ($9)    11 C ($10)    13 D ($6)    9 E ($4)    3 Main Course: R ($20)    13 S ($25)    23 T ($21)    14 U ($15)    8 V ($18)    12 Desert: I ($3)    5 J ($4)    6 K ($5)    8 L ($7)    9 M ($8)    11 Here is a generic function that does the work in C#. public void GetMaxDesirability(int N) { ArrayList ar = new ArrayList(); double sm = 0; Hashtable ht1 = new Hashtable()...

Simple enough algorithm ☻

The problem statement is to choose the maximum of one or more among three candies A, B and C priced respectively at 0.59, 0.79 and 0.95, such that you can procure the value closest to $4.00. The solution is pretty simple if you consider that there are 7 possibilities (mutually exclusive) depending on whether you choose one / two / three types of candies. The solution in C# is listed below. Note : FindMax2 is a simple function (implementation not listed) that can be used to find the maximum value from the ArrayList. //there are 7 combinations ArrayList ar = new ArrayList(); double sm = 0; //Loop 1 for (int i = 7; i >= 1; i--) { sm = i * 0.59; if (sm > 4) { continue; } else { ar.Add(sm); } } //Loop 2 for (int i = 7; i >= 1; i-...

Simple enough algorithm

The problem statement is to choose the maximum of one or more among three candies A, B and C priced respectively at 0.59, 0.79 and 0.95, such that you can procure the value closest to $4.00. The solution is pretty simple if you consider that there are 7 possibilities (mutually exclusive) depending on whether you choose one / two / three types of candies. The solution in C# is listed below. Note : FindMax2 is a simple function (implementation not listed) that can be used to find the maximum value from the ArrayList. //there are 7 combinations ArrayList ar = new ArrayList(); double sm = 0; //Loop 1 for (int i = 7; i >= 1; i--) { sm = i * 0.59; if (sm > 4) { continue; } else { ar.Add(sm); } } //Loop 2 fo...