I once overdosed on Sudoku for about three weeks. All of the following programs are written by me, so all praise and blame should be directed to me as well.

Ruby Sudoku - Because I wanted to learn Ruby
C Sudoku - Because I thought the Ruby version was too slow
Java Sudoku - Because I taught a class in Java
Python Sudoku - Because I taught a class in Python
Scala Sudoku - Based on a recommendation from my professor
Fortran Sudoku - Because I had a job interview requiring a background in FORTRAN

To use any of my Sudoku solving algorithms, you'll need to provide a unsolved puzzle in the proper format. This format is simply a 9 by 9 grid of numbers 0 through 9 with a space between each number, where 1-9 are the predefined values of the puzzle and 0 represents a blank square.

The following are some sample input puzzles. I would type them into a text editor (like Notepad) and then run the program from the command line.

Note: All of the versions here work for 9 by 9 grids, with the exception of the Scala implementation. The Scala implementation will work on any n^2 by n^2 size puzzle. It has been tested with 9 by 9, 16 by 16, and 25 by 25 puzzles.

For the C version:

cc sudoku.c -o sudoku
./sudoku < easypuzzle

For the Ruby version:

ruby sudoku.rb < easypuzzle

For the Java version

javac sudoku.java
java sudoku < easypuzzle

For the Python version

python sudoku.py < easypuzzle

For the Scala version

scalac sudoku.scala
scala SudokuApp < easypuzzle

For the FORTRAN version

gfortran sudoku.f90 -o sudoku
./sudoku < easypuzzle

Easy Puzzles:

4 0 0 9 0 0 0 7 0
0 0 0 6 0 1 0 0 3
0 2 6 0 3 4 9 1 0
0 0 0 2 4 5 0 0 0
2 0 0 0 0 0 0 0 1
0 0 0 7 1 9 0 0 0
0 3 8 1 2 0 6 4 0
6 0 0 4 0 8 0 0 0
0 4 0 0 0 3 0 0 7

Medium Puzzles:

1 0 0 8 0 0 0 3 0
7 0 0 0 0 0 0 2 0
0 0 0 5 6 0 0 7 0
0 0 8 0 0 0 9 0 0
0 0 5 2 1 7 4 0 0
0 0 4 0 0 0 7 0 0
0 3 0 0 8 9 0 0 0
0 2 0 0 0 0 0 0 8
0 8 0 0 0 4 0 0 6

0 0 0 0 0 0 0 1 4
2 0 0 5 0 0 6 0 0
9 0 0 3 0 0 0 0 0
0 5 0 0 1 0 0 3 0
0 8 0 0 3 0 0 7 0
0 6 0 0 2 0 0 9 0
0 0 0 0 0 8 0 0 2
0 0 3 0 0 4 0 0 1
5 7 0 0 0 0 0 0 0

Hard Puzzle:

0 0 0 0 0 0 2 0 0
0 0 5 7 0 0 9 6 0
8 0 4 0 6 0 0 3 7
9 0 0 0 1 6 0 0 0
0 0 0 8 0 7 0 0 0
0 0 0 3 9 0 0 0 6
4 6 0 0 8 0 5 0 1
0 1 7 0 0 4 6 0 0
0 0 3 0 0 0 0 0 0

Very Hard Puzzles:

0 5 4 0 0 7 0 0 0
0 6 0 0 0 1 0 0 0
0 0 0 2 0 0 3 0 8
0 0 9 5 0 0 0 3 0
0 0 3 0 9 0 2 0 0
0 7 0 0 0 2 9 0 0
7 0 5 0 0 6 0 0 0
0 0 0 4 0 0 0 5 0
0 0 0 1 0 0 8 9 0
0 8 0 0 0 5 0 3 0

0 0 0 3 8 0 0 0 0
7 0 0 0 0 4 0 5 0
4 0 0 0 0 9 0 0 0
3 0 5 0 0 0 8 0 6
0 0 0 2 0 0 0 0 4
0 9 0 5 0 0 0 0 3
0 0 0 0 1 7 0 0 0
6 7 0 9 0 0 0 2 0
0 0 0 3 0 8 0 9 6


Page Information

  • 3 months ago [history]
  • View page source
  • You're not logged in
  • Tags: code sudoku

Wiki Information

Recent PBwiki Blog Posts