Hacker News new | ask | show | jobs
by kjeetgill 2833 days ago
I love this.

Writing a sudoku solver is my go to for learning new programming languages. I just write the most basic algorithm: solve obvious squares with only one answer, then guess and repeat. Backtrack your guess if you end up in an unsolvable case.

It forces you to touch on enough different language features to really get comfortable. Arrays/basic data structures, calling recursive functions, deep copying stuff, fork/join style parallelization (and cancelation if you want).

It's just tricky enough to make you taste some of the code management features like classes and interfaces and the like too.

If you're trying to learn OOP vs. functional programming I think it's a great way to really feel the strength and pain points of both.

1 comments

My first effort was the same but without backtracking. I would make a random guess at each step and propogate constraints on the board. If it ever got stuck as unsolvable, I would just start it over again. Most solved very quickly, the highest number of tries I had was something like 2100.