Generating and replaying solutions using Unix shell scripting




My encounters with Sudoku are infrequent, typically limited to the puzzle page within in-flight magazines. Not surprisingly, the time-tribute a difficult game extracts from the Sudoku novice in me can spill into hours. It's as though Karma steps in to compensate the rare visits to the game by enforcing long stays for each visit! :)

A few recent puzzles happened to be especially unkind. It was therefore time to heed the proverbial advice of making lemonade when handed lemons:  My way of getting back at Sudoku puzzles was going to be a program that could tackle even the most evil of them! 

Having earlier done similar coding for fun with chess (8 Queens problem) and Scrabble (7 and 8 letter words with a given set of tiles), the expectation was for it to be quick and easy. However, multiple solving techniques and the sheer range of number combinations that can exist on an innocent-looking 9x9 square do make it slightly more challenging. 

As the solution video shows, my program starts off by iteratively populating vacant squares by 3 Sudoku techniques.  When successive iterations of these methods stop yielding improvement, it initiates a phase of trying out different candidate values for a suitable empty square, and resuming the solving techniques and backtracking when it hits a dead end. To eliminate as many dead end branches as possible, it selects a square with the lowest count of potential candidates at the start of the trial phase. 

I'm sure my choice of korn shell and numerous file operations leave many opportunities for speeding up the code execution. Years of DBA experience can make one OCD at times with performance tuning opportunities. Yet for this time, all that matters is that my script seems to beat any Sudoku flung at it! Vinay 1, Sudoku 0. :D