Wednesday 29 May 2013

Tracing an object using Decorator Design Pattern


Decorator Pattern is a design pattern used for adding a feature to an object implementing an interface in an non intrusive way either statically or dynamically. In other words the decorator pattern can be used to extend (decorate) the functionality of a certain object statically, or in some cases at run-time, independently of other instances of the same class, provided the object creation is done using a decorator object.

Thursday 23 May 2013

Numbering the CDs Puzzle



A friend of mine works in a data management company and he needs to compulsively records  all the backuped data on CD Roms. To this end, he has a huge collection of CD ROMs. He has long given up on trying to label these cassettes with any meaningful names. Now he just numbers them and maintain the description based on number given to CD else where. The numbers go from 1 up and are consecutive.

Sunday 19 May 2013

The Golf Score Puzzle


Three friends Andrew, watson and Lestrade were playing Golf. Andrew made three statements regarding their scores for a particular round. Can your work out their individual score??

Friday 17 May 2013

Prisoners and The Switch Room Puzzle


A prison jailor meets with the twenty three convicts when they arrive at the prison. He tells them:

You may meet today to discuss and plan a strategy, but after today you will be locked in isolated cells and have no communication with one another.

There is in this prison a "switch room" which contains two light switches, labeled "A" and "B", each of which can be in the "on" or "off" position. I am not telling you their present positions. The switches are not connected to any appliance. After today, from time to time, whenever I feel so inclined, I will select one prisoner at random and escort him to the "switch room", and this prisoner will select one of the two switches and reverse its position (e.g. if it was "on", he will turn it "off"); the prisoner will then be led back to his cell. Nobody else will ever enter the "switch room".

Thursday 16 May 2013

Imagining the Tenth Dimension


I still remember the day when my Maths teacher tried to explain about dimensions when I was in high school. Visualizing the first, second and third dimension was easy, but then I asked him, Can there be a fourth dimension? His answer was yes, It was difficult for me to understand then. He tried to explain the concept using example of a Tesseract(Shown Below), still it was very abstract for me to assimilate the concept. In fact he told that there can be a fifth and higher dimension. And infinite dimension is nothing but God himself.

Saturday 11 May 2013

Mysteries and Beauty of Fractals


Its really amazing to know know how a simple equation zn+1 = zn2 + c can create patterns which are so intricate, so vivid and so beautiful. The set defined by above equation is know as Mandelbrot set and it represents a set of points denoted by c in a complex plane for which zn+1 remains always bounded starting with  z= 0. 

Thursday 9 May 2013

Going Native - Talk by Bjarne Stroustrup on C++11

"The world runs on C and C++". And hearing from the master himself about it is so enlightening. His emphasis on simple and clean code, explanation of new C++ 11 features and crisp examples to showcase them will encourage many to take a fresh view at the language.  The examples on type rich programming and move constructor are very interesting and that is something I look forward to use. The STL example on vector breaks my conventional understanding of the STL libraries, though I am a avid user of STL libraries myself, I always had a concern that they may not be fast. But thanks to his explanation my belief in STL is vindicated.
This presentation is quite long(Around 90 Mins) so preferably watch it at your leisure and get enlightened..



Tuesday 7 May 2013

TSP Simulator based on Simulated Annealing Technique


Traveling Salesman Problem is one of the very interesting topics among algorithm enthusiast. The problem definition is very simple. Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city? It is an NP hard problem with no polynomial time algorithm known till date. It finds several important real life application such as routing and floor planning of Integrated Circuits, Mechanical Arm sequencing etc.
More regarding this interesting problem can by found on Wikipedia(TSP).
Simulated Annealing algorithm is a generic probabilistic metaheuristic technique for the global optimization problem of locating a good approximation to the global optimum of a given function in a large search space. Simulated Annealing can be used for solving several optimization problems. TSP is one of them.


Friday 3 May 2013

A Sudoku Solver


For quite sometime Sudoku has become a one of the most enjoyable pass time for many people and they are visible every where. We are having daily Sudoku in newspaper, several online website where we can play Sudoku and several apps for hand held devices on android and Apple app store.  In principle I knew how to solve a Sudoku and have tried several of them as well. But I wanted to code my thought process for a computer to do the job for me. Hence I ended up writing my own Sudoku solver.

The solver employs back tracking algorithm to solve a given Sudoku. Moreover if the Sudoku is not a valid one or if it cannot be solved then this programs reports that as well and exits. The idea of sharing this post is to let the users understand how a back tracking algorithm works and how it can be put in code using a stack. The pseudo code for the algorithm is as below:

Thursday 2 May 2013

Ten Assertions Puzzle

Fill in the blanks with numbers so that all the statements are true.

Number of occurrences of the digit 0 in this puzzle is  _____.
Number of occurrences of the digit 1 in this puzzle is  _____.
Number of occurrences of the digit 2 in this puzzle is  _____.
Number of occurrences of the digit 3 in this puzzle is  _____.
Number of occurrences of the digit 4 in this puzzle is  _____.
Number of occurrences of the digit 5 in this puzzle is  _____.
Number of occurrences of the digit 6 in this puzzle is  _____.
Number of occurrences of the digit 7 in this puzzle is  _____.
Number of occurrences of the digit 8 in this puzzle is  _____.
Number of occurrences of the digit 9 in this puzzle is  _____.