News for hackers. Stuff that matters.
Re:From Sudoku Solver to Program Synthesis by Isamu on Thursday February 21, 2019 @10:04AM (#19217289)
When I wrote a Sudoku solver I was disappointed to find that backtracking worked maybe too well; that is, I coded in the minimum constraints to follow the rules of the game and then added backtracking and voila, it found solutions quickly enough.

Why was I disappointed? Because initially I wanted to write a solver that inferred more, that used the inferences that I made when solving Sudoku.

Sadly once the solver worked, I kinda lost interest.

I hate backtracking myself and it should only be necessary at a certain Sudoku hardness level - every puzzle below that level of hardness should be solvable without backtracking.

Re:From Sudoku Solver to Program Synthesis by dahart on Thursday February 21, 2019 @12:48PM (#19218834)
Yep, backtracking works fine. If you only want the solution, then you don't need complex rules. But, you really want more than just the solution.

Check out http://sudokuwiki.com/sudoku.htm

This solver (and the whole site) is the best one I know of, and it will solve a puzzle by using rules in order of difficulty, to guarantee it tries the simple rules you know before resorting to backtracking.

The benefits of this are that you can grade the difficulty of a sudoku board. You can also solve a puzzle up to the "crux" and then work on only the hard moves manually. I like doing that so I can skip the hours of boring stuff and practice doing the more tricky inferences. Andrew's site is a window into how big of a rabbit hole Sudoku can be...

Re:From Sudoku Solver to Program Synthesis by akbo on Thursday February 21, 2019 @01:41PM (#19219368)
If you are interested in grading Sudokus by the difficulty of the human solving techniques required, you might want to check out the following two books:

- "Sudoku Programming with C" [https://www.apress.com/de/book/9781484209967] where a Sudoku solver and grader is implemented.

- "A to Z of Sudoku" [https://www.wiley.com/en-us/A+to+Z+of+Sudoku-p-9781847040008] where many human solving techniques are described and rated by their difficulty.

Re:From Sudoku Solver to Program Synthesis by daxfohl on Thursday February 21, 2019 @11:44AM (#19218111)
You can make it harder by using 16x16, 25x25, 36x36 etc boards, and see how fast you can make it. There are lots of known patterns to allow for elimination of options http://www.sudokuwiki.org/Getting_Started, of different computation complexity relative to each other, and all faster than regular backtracking. So the goal is to find the order at which to apply them for maximum speed and minimal need to backtrack. You can also try to multithread and use GPU, or FPGA if you're nuts.

All that said, it's all still pretty mechanical. So if you're looking for something more inferential, then another game would be better.

Re:From Sudoku Solver to Program Synthesis by LanceH on Thursday February 21, 2019 @12:22PM (#19218502)
My first attempt did no backtracking at all. It would guess randomly, propagate constraints and continue. If it got stuck, it would just start again. The most it ever took to solve a puzzle was 2100 attempts. Sure it wasn't guaranteed to solve a puzzle in finite time, but it worked well enough for something written during one of those endless big-corp conference calls.
Re:From Sudoku Solver to Program Synthesis by karmakaze on Thursday February 21, 2019 @09:14PM (#19222548)
Technically, this is backtracking... to move 1.
Re:From Sudoku Solver to Program Synthesis by pdwetz on Thursday February 21, 2019 @11:41PM (#19223189)
Backtracking as a strategy definitely seems... underwhelming. But it does have its uses. I wrote a few solvers, and they all served a different purpose. One was based on Norvig's python post on the subject; I used that to generate many puzzles very quickly. Then I used a backtracker (using Knuth's Dancing Links) to reduce the set to puzzles with only a single solution. The last solver was a "human" solver that used various known strategies; this let me grade difficulty without having to manually attempt every puzzle (although I still found it useful in my app UI to tag puzzles as being too hard/easy). The human solver is incredibly inefficient, but the one with the most room for growth (new strats, etc).
Re:From Sudoku Solver to Program Synthesis by saurabh20n on Thursday February 21, 2019 @10:57AM (#19217681)
You are absolutely right. Punching "extra holes" in puzzles of certain hardness should make backtracking not as viable. But we'll loose the unique solution property.

Might make it more interesting? And maybe even bias it towards human-abilities. I think intuitively we're better at solving when the possibilities are more than 1 (just a conjecture.)

Re:From Sudoku Solver to Program Synthesis by wiredfool on Thursday February 21, 2019 @11:13AM (#19217806)
My soduku solver from ca~10 years back ran the "hardest" soduku puzzles in < 10 seconds on a netbook atom processor. IIRC, the hardest one that I ever threw at it had 7 levels of backtracking.

It's just not that hard of a problem compared to the speed of computers.

Re:From Sudoku Solver to Program Synthesis by posterboy on Thursday February 21, 2019 @02:44PM (#19219894)
this comment made me lose interested, too, even my interest in the article.