Solving Every Sudoku Puzzle (2006)
norvig.com
Solving Every Sudoku Puzzle (2006)
1–10 of 28 posts
Re: Solving Every Sudoku Puzzle (2006)
#2Re: Solving Every Sudoku Puzzle (2006)
#3This is good to know that we can win Sudoku with a computer program but not surprising. The goal of Sudoku is to make your intellect work and find logic by yourself. The article should be named: How to win every Sudoku puzzle by cheating.
Re: Solving Every Sudoku Puzzle (2006)
#4Sudoku solver in three lines of Perl (golf): https://web.archive.org/web/20070106133158/http://www.eccles...
use integer;@A=split//,;sub R{for$i(0..80){next if$A[$i];my%t=map{$_/9
==$i/9||$_%9==$i%9||$_/27==$i/27&&$_%9/3==$i%9/3?$A[$_]:0=>1}0..80;R($A[
$i]=$_)for grep{!$t{$_}}1..9;return$A[$i]=0}die@A}RRe: Solving Every Sudoku Puzzle (2006)
#5This is good to know that we can win Sudoku with a computer program but not surprising. The goal of Sudoku is to make your intellect work and find logic by yourself. The article should be named: How to win every Sudoku puzzle by cheating.
Re: Solving Every Sudoku Puzzle (2006)
#6This is good to know that we can win Sudoku with a computer program but not surprising. The goal of Sudoku is to make your intellect work and find logic by yourself. The article should be named: How to win every Sudoku puzzle by cheating.
Re: Solving Every Sudoku Puzzle (2006)
#7Here are some other sudoku solvers that give more insight into the coder than the problem:
Sudoku in APL: https://www.youtube.com/watch?v=DmT80OseAGs
Test driven sudoku: http://ronjeffries.com/xprog/articles/sudokumusings/
Re: Solving Every Sudoku Puzzle (2006)
#8For example (2x2 sudoku = 4 sheets):
1324
3142
4213
2431
is: 1... .2.. .3.. ...4
.1.. ...2 3... ..4.
..1. + .2.. + ...3 + 4...
...1 2... ..3. .4..
or even: x... .x.. .x.. ...x
.x.. ...x x... ..x.
..x. + .x.. + ...x + x...
...x x... ..x. .x..
x... .x.. ..x. ...x
where the last "number row" does not belong to the grid but serves to indicate the number of the sheet.This explains how sudoku relates to the Exact Cover problem. Now, there is a good algorithm by Knuth to solve Exact Cover, which is known as Algorithm X [2].
Algorithm X is just an algorithm but Knuth has also invented a very efficient implementation of it, called Dancing Links or DLX for short [3]. DLX is described in a very good and very readable paper by Knuth himself [4]. This is one of the first serious papers I ever read and it was a real joy, mind-opener.
[1] https://en.wikipedia.org/wiki/Exact_cover
[2] https://en.wikipedia.org/wiki/Knuth%27s_Algorithm_X
[3] https://en.wikipedia.org/wiki/Dancing_Links
[4] http://www-cs-faculty.stanford.edu/~uno/papers/dancing-color...
Re: Solving Every Sudoku Puzzle (2006)
#9Re: Solving Every Sudoku Puzzle (2006)
#10I've noticed that solving a sudoku is something of a rosetta stone for how people program. Norvig's solution is very straightforward in hindsight, but I think that code was either the result of many iterations or of a career of making progressively more readable code. Here are some other sudoku solvers that give more insight into the coder than the problem: Sudoku in APL: https://www.youtube.com/watch?v=DmT80OseAGs T…
In any case, I'm replying to your comment because it applies to me. Norvig's code is compact and elegant, whereas mine is spaghetti code at best. I basically have lots of control statements, as there are many many processing steps that I painstakingly discovered as I went along (thousands of lines). Heck, I can barely remember them myself.
Here's my site: http://sudokuisland.com