Hacker News new | ask | show | jobs
by o11c 616 days ago
From the linked page (and the one linked beyond that), it's a breadth-first search actually. Keep a list of possible puzzle states at all times, pick a blank cell (theoretically arbitrary, but in practice intelligently for performance), add copies of the state with each possibility for that state added.
2 comments

That sounds like 100+ lines in python or similar languages…
You should be able to do it in under 20 lines using the same matrix operations as the K code via numpy.
Numpy is indeed very apl. Just more horrible to me; not python-y and annoyingly verbose for the apl-er.
A few years back I made a modest attempt at writing a concise yet readable sudoku solver in Python - in about 29 lines: https://github.com/hrzn/sudoku/blob/master/sudoku.py

Could have been made shorter at the price of readability.

Looks nice. Since imports numpy can utilize (more of) numpy's operations to squeeze validation functions and nested fors to one. Should result in shorter code but readability will probably depend on reader's experience in array programming.
It probably isn't. At least, not for Python.
The k code at least isn't doing any heuristics for the iteration order, and is just doing a fold over the indices of zeroes in index-ascending order.