How to Solve Sudoku using Hadoop ?
Hadoop has provides an example jar file for test purposes. In this jar file there is an example to solve sudoku problems.
1. Input File
To use this example we need to make an input file for the sudoku problem. In this file each sudoku cell can be either a number or ‘?’ with spaces as separators.Like this one:
File : puzzle1.dta
8 5 ? 3 9 ? ? ? ?
? ? 2 ? ? ? ? ? ?
? ? 6 ? 1 ? ? ? 2
? ? 4 ? ? 3 ? 5 9
? ? 8 9 ? 1 4 ? ?
3 2 ? 4 ? ? 8 ? ?
9 ? ? ? 8 ? 5 ? ?
? ? ? ? ? ? 2 ? ?
? ? ? ? 4 5 ? 7 8
You can find this “puzzle1.dta” file in Hadoop directory :
hadoop-0.20.2/src/examples/org/apache/hadoop/examples/dancing/puzzle1.dta
or
hadoop-2.0.0-alpha-/src/hadoop-mapreduce-project/hadoop-mapreduce-examples/
src/main/java/org/apache/hadoop/examples/dancing/puzzle1.dta
2. Hadoop Part
Now we need to save this input file in our local directory. And give this input to hadoop example jar. Start hadoop and run this command:
$hadoop-directory/bin/hadoop jar hadoop-examples-version.jar sudoku puzzle1.dta
Solving puzzle1.dta
8 5 1 3 9 2 6 4 7
4 3 2 6 7 8 1 9 5
7 9 6 5 1 4 3 8 2
6 1 4 8 2 3 7 5 9
5 7 8 9 6 1 4 2 3
3 2 9 4 5 7 8 1 6
9 4 7 2 8 6 5 3 1
1 8 5 7 3 9 2 6 4
2 6 3 1 4 5 9 7 8
Found 1 solutions
Hadoop give you the all possible solutions for the puzzle in a few seconds.( If there is more than one answer the time will be higher).
Note
You must give the local path to hadoop( In this example jar file and puzzle in the same directory)
You must give the local path to hadoop( In this example jar file and puzzle in the same directory)
If you have questions,you can write a comment to me…
very nice! Thankz
Hi i am new in hadoop +hbase, can you tell how to retrieve data from mutibletable in hbase using mapreduce and spring
hi!
good solution, but have you fogotten to put the code??
Regards
you can find the source codes inside hadoop download file.
hadoop-0.20.2/src/examples/org/apache/hadoop/examples/dancing/Sudoku.java
this is the path for hadoop-0.20.2 version.
may be you should read more about hadoop -> http://hadoop.apache.org/