Stateful Solvers and Iterators

Rust, yet again! Let’s take what we did last time with Solving Sudoku (again) and improve the code structure a bit more.

Goals:

  • Create a ‘Solver’ struct that can maintain state (such as how many states we’ve visited, how much time we’ve spent)
  • Track the above stats
  • Turn the ‘Solver’ into an iterator which will iterate through given solutions (a single call will give the first solution or you can run through the iterator to get all of them)

If you’d like to follow along, I’ve started uploading the code here: https://github.com/jpverkamp/rust-solvers

read more...


Immutable.js Solvers

A bit ago I wrote about writing a generic brute force solver (wow, was that really two months ago?). It got … complicate. Mostly, because every time I wrote a step function, I had to be careful to undo the same. Wouldn’t it be nice if we could just write a step function and get backtracking for ‘free’?

Well, with immutability you can!

read more...