Showing posts with label BackTracking. Show all posts
Showing posts with label BackTracking. Show all posts

Tuesday, 9 July 2013

Bowling Pin Arrangement Puzzle

Once you went to bowling with your friend. All the bowling pins were labelled with different integer from 0,1,2 .. to 9. The arrangement of pins (in a triangle form) was very interesting. If two pins are side-by-side, the sum of their labels (reduced modulo 10) is equal to the label of the pin in front and between them. For Example
1   2   4   5
  3   6   9
   9   5
   4


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: