# 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)

# Solving Sudoku (again)

More Rust! This time, I want to go back to my post on A Generic Brute Force Backtracking Solver. For one, because I’m learning Rust. For two, because there is a crate specifically for im mutable data structures. And for three, because I expect it will be much faster. We shall see!

# Solving Snakebird

Snakebird!

A cute little puzzle game, where you move around snake(birds). Move any number of snakes around the level, eating fruit, and getting to the exit. The main gotchas are that you have gravity to content with–your snake will easily fall off the edge of the world–and each time you eat a fruit, your snake gets bigger. This can help get longer to get into hard to reach places or it can cause trouble when you trap yourself in corners.

Let’s use the new immutable.js solver to solve these problems!

# 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!

# AoC 2017 Day 15: Two Generators

### Source: Dueling Generators

Part 1: Create a pair of generators A and B where:

• A_n = 16807 A_{n-1} \mod 2147483647
• B_n = 48271 B_{n-1} \mod 2147483647

How many of the first 40 million values have matching values for the low 16 bits of each generator?