| Problem statement | Source code | Tags: Cellular automata
Not much to say about this one; it's a straightforward simulation. Like any other cellular automata problem, due to the potentially infinite grid, I represent the map as a Set (Int, Int).
I let the elves each propose a move. If it has no neighbors, it doesn't move. Otherwise, it uses the first valid direction in the current round's order.
Then, I count the proposed moves and only execute those that are unique (moveCounts is 1), and finally rotate the directions.
Now I just need to execute moveElves 10 times.
The easy way out is to just keep executing moveElves, each time comparing the new set of elves to the old one. This is a bit slow though, so I augmented moveElves to also return a boolean indicating whether any elves moved.
Now I can execute until no elves move: