Last week I was reading my friends blog Robot Dan
and came across his sudoku post.
I’ve never written a sudoku solver before, naturally I thought of writing it in
Elixir. I spent the evening playing around trying to come up with something that
was at least somewhat idomatic.
My first solution was a very similar implementation to what Dan had on his site.
It works ok. I found a harder board that made it take a bit longer.
Interestingly I found that the memory usage was flat for easy or hard. I’m
guessing that I got the tail recursion correct.
I wanted to do something a little more Elixiry though. When the recursive
function selects all possible values for a cell, and then recurses, that’s the point that I thought
I might be able to shoot out a bunch of processes and do all the calculations in
parallel. A branching recursive parallel implementation. Sounded fun!
I implemented it using Elixir Tasks and process dictionaries.
Unfortunately I went wrong somewhere. I ran out of processes, or simply timed
out. I even increased the number of processes to 5M without helping. It maxed
out in RAM, CPU and times out.
I think I’ll stick with the recursive solution, but I’ve included the other
below.