top | item 19216349

From Sudoku Solver to Program Synthesis

48 points| saurabh20n | 7 years ago |synthetic-minds.com

22 comments

order
[+] Isamu|7 years ago|reply
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.

[+] dahart|7 years ago|reply
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...

[+] daxfohl|7 years ago|reply
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.

[+] LanceH|7 years ago|reply
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.
[+] pdwetz|7 years ago|reply
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).
[+] saurabh20n|7 years ago|reply
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.)

[+] posterboy|7 years ago|reply
this comment made me lose interested, too, even my interest in the article.
[+] sevensor|7 years ago|reply
So is this meant to be an advertisement for their product, or are they trying to recruit? Why are they trying to filter for people who can write a sudoku solver?
[+] saurabh20n|7 years ago|reply
We are looking for people who want to play around with constraint solvers. As others in this thread have mentioned, the vanilla Sudoku is not hard to really need constraint solvers; a generalized version would. We don't expect people to have backgrounds in program synthesis, but constraint solving is a start.

That said, it is just a fun problem. PTime specialized solutions are even more intriguing.

[+] x11|7 years ago|reply
Just how long more should I leave my solver running ?
[+] Avery3R|7 years ago|reply
Don't hijack scrolling.
[+] saurabh20n|7 years ago|reply
We don't. Which browser/OS are you seeing this on?
[+] sigstoat|7 years ago|reply
now that my solver has been chugging along for awhile, and i'm sort of bored of fiddling around with the supporting bits, i find myself wondering: since there's a politely-requested limit on submission rate, isn't the person who solves the most basically just the one who wrote an automatic solver fastest and/or leaves it running the longest?
[+] sigstoat|7 years ago|reply
well, you guys were sneakier than i initially expected, and clearly more clever than me, as i can't figure out the pattern. oh well.
[+] yazr|7 years ago|reply
TLDR : we use a solver to go from a formal constraint specification to an Ethereum smart contract

So 1. the initial specification is still a formal constraint

  2. the domain complexity is low  

  3. Use well known solvers to generate code in a DSL
[+] saurabh20n|7 years ago|reply
This page was just a fun exercise; seems to have missed communicating fully how we use synthesis. My bad.

You are right about about "2." and part of "3.". For "2." yes, the smart contracts are indeed simpler (small code, gas limits, closed systems). So we can skip some major hurdles that more general techniques need -- case in point the FB abstract interpretation framework Sparta here yesterday. For "3." we use Z3 (as should everybody :)!) but the target language for synthesis is Solidity. [ Hope you didn't mean Solidity is a DSL, coz that would be a generous interpretation of that word. ]

The initial spec is another smart contract (call it IN), so code and not a formal constraint. We synthesize another smart contract (call it OUT), such that the combination (IN + OUT) behaves well. See work on synthesizing program inverters for the background ideas (http://saurabh-srivastava.com/pubs/pldi11-pins.pdf)