Live data from Hacker News

Solving Every Sudoku Puzzle (2006)

norvig.com

21–30 of 101 posts

Re: Solving Every Sudoku Puzzle (2006)

#21
An oldie but a goodie.

The other day we were at a restaurant and they gave my four year old a kids menu. One of the activities was a modified sudoku that went up to 6. My first thought was that I'd never realized you could do sudokus with other values of N.

But the really cool part was that once I taught her the rules (the constraints) she was actually able to figure it out without much help at all!

Turns out sudoku is a good way to teach kids logic, even at four years old.

Re: Solving Every Sudoku Puzzle (2006)

#22
post #20

> As computer security expert Ben Laurie has stated, Sudoku is "a denial of service attack on human intellect". Several people I know (including my wife) were infected by the virus, and I thought maybe this would demonstrate that they didn't need to spend any more time on Sudoku. That's hilarious! But what puzzles, or even activities wouldn't be classified by Ben as a DOS on humans?

Tic-tac-toe? :)

Re: Solving Every Sudoku Puzzle (2006)

#23
post #19

Earlier quoted context omitted.

While dancing links is cool, when benchmarking it turns out using bits to represent values, and just copying, ends up being faster. This is because on modern CPUs about the worst thing you can do is lots of pointer following.

I wrote a (straightforward) dancing links implementation that solves 17.000 puzzles/sec/core. It also validates uniqueness of the found solution. How much faster does it get? I'm genuinely curious

Counting based on problems is tricky, as it depends how hard the problem is. When I implemented, I got about 4x faster with bit packing.

Re: Solving Every Sudoku Puzzle (2006)

#24
post #21

An oldie but a goodie. The other day we were at a restaurant and they gave my four year old a kids menu. One of the activities was a modified sudoku that went up to 6. My first thought was that I'd never realized you could do sudokus with other values of N. But the really cool part was that once I taught her the rules (the constraints) she was actually able to figure it out without much help at all! Turns out sudoku…

A long time ago I did high school math instruction. I used Sudoku for an initial introduction to proofs - something where the student knew they were implicitly going through a "proof" process.

Re: Solving Every Sudoku Puzzle (2006)

#25
post #19

Earlier quoted context omitted.

While dancing links is cool, when benchmarking it turns out using bits to represent values, and just copying, ends up being faster. This is because on modern CPUs about the worst thing you can do is lots of pointer following.

I wrote a (straightforward) dancing links implementation that solves 17.000 puzzles/sec/core. It also validates uniqueness of the found solution. How much faster does it get? I'm genuinely curious

There is a collection of benchmarks of the fastest sudoku solvers here: https://github.com/t-dillon/tdoku/tree/master/benchmarks

How fast they are depends on the difficulty of the sudoku and on your machine, but it's typically a few thousand/s on the hardest known and several 100k/s to a million/s on very easy.

Re: Solving Every Sudoku Puzzle (2006)

#26
post #21

An oldie but a goodie. The other day we were at a restaurant and they gave my four year old a kids menu. One of the activities was a modified sudoku that went up to 6. My first thought was that I'd never realized you could do sudokus with other values of N. But the really cool part was that once I taught her the rules (the constraints) she was actually able to figure it out without much help at all! Turns out sudoku…

Aha yes! When I wrote my first sudoku solver a decade ago I was having fun and decided to stress test my solver with bigger N. I found a site dedicated to these and with puzzles as large as 64x64.

Re: Solving Every Sudoku Puzzle (2006)

#28
post #21

An oldie but a goodie. The other day we were at a restaurant and they gave my four year old a kids menu. One of the activities was a modified sudoku that went up to 6. My first thought was that I'd never realized you could do sudokus with other values of N. But the really cool part was that once I taught her the rules (the constraints) she was actually able to figure it out without much help at all! Turns out sudoku…

Binary Sudoku - https://xkcd.com/74/

Re: Solving Every Sudoku Puzzle (2006)

#29
post #6

Sudoku solvers are near and dear to my heart. They’re my go to problem when learning a new programming language because they’re just complex enough to exercise a whole bunch of different language features. I built this when I wanted to learn Swift and dip my toe into machine learning: https://twitter.com/braddwyer/status/910030265006923776?s=21

For me, my go to problem tends to be a simplistic lisp interpreter.

Re: Solving Every Sudoku Puzzle (2006)

#30
The key insight when writing a sudoku solver is that it is just depth first search. Once someone told me that it just sort of clicked. Just guess each possible number at each open square and if you ever get to an un-solvable state, just undo the last change you made and try the next one. I was extremely satisfied with myself after writing my first really clean solver with backtracking.

I'm sure there are other, more efficient, ways to write sudoku solvers, but the simplicity and clarity the DFS solver offers is pretty cool IMO.

Post reply on HN