UK newspapers are awash with Sudoku, a number puzzle. My paper carried this puzzle today:
You have to fill in the blanks so that the numbers 1 to 9 appear once in each row, once in each column and once in each 3x3 square. You're meant to solve it by brain power, but I get bored too quickly. Writing Java code keeps my attention, though. I'm sure that what I did it could be improved in any number of ways, but it finds the solution pretty quickly by brute force (i.e. lots of guessing).
( My code here - don't peek if you want to try it yourself...Collapse )
Curiously, the puzzle above took more guesses than any other I've tried, but wasn't rated by the newspaper at the hardest difficulty level.
Even more curiously, the compiler produces an anonymous inner class file (Sudoku$1.class) which I can't tie to any part of my code, and which doesn't seem to be required at run time (because if I delete it, nothing goes wrong).