I had a hunch I could use mod, but I wanted to try something different and represent a “ring” instead and try to have “inspectable” output at each step.
I’m active on lemmy: https://programming.dev/c/advent_of_code and am posting my solutions in the daily solution threads.
There are also some other Haskell solutions, for Day 1, I think there were three or four.
I’m using this to brush up on Rust this year. Probably doing everything in Haskell first, then translating. Repo is here. It’s a fairly nice setup with a Nix flake (haskell.nix + crane) and tasty-golden for tests.
You can find my solutions here: Only the first four days are in Haskell. I switched to Futhark afterwards because I wanted to try and learn something new.
I am stuck on Day 10 Part 2, with the puzzle input, and, consequently, can’t reach Day 12 Part 2.
I can see that the Part 2 puzzle reduces to an integer linear programming problem. So, first, I investigated linear programming libraries, in the (vain) hope that the real solutions would also be integer solutions (as in the case of the example input).
I tried simplex-method-0.2.0.0, but it did not seem to be able to cope even with the example input (perhaps I did something wrong).
Then I tried coinor-clp-0.0.0.2, which is a Haskell wrapper around a C++ library (COIN-OR/CLP). That worked (which is how I found relying on real solutions would be in vain), but not without some complexity on Windows: the MSYS2 project does not provide the C++ library for the MINGW64 environment (Stack’s default) but for others. I shifted my Stack set-up to be in the UCRT64 environment (it took me a while to realise that would require a clean slate).
At that point, I thought the C++ library COIN-OR/CBC (a mixed integer linear programming solver) could be a solution. The MSYS2 project provides it. I tried limp-cbc-0.3.2.3 (uploaded to Hackage in 2018), which is a Haskell wrapper around it, but it either (1) failed to build (with Cabal flag embedded set) or (2) failed with Access violation in generated code when executing data at 0x0 (with the Cabal flag unset). I gave up on that package.
Finally, I thought I would try returning to COIN-OR/CLP augmented with my own attempt at a ‘branch and bound’ algorithm. That worked for some items but, for others, the branching exploded (again, perhaps I did something wrong).
Those are my dead ends. I’m now going to ‘cheat’ by looking at what other Haskellers did.
Interesting! By looking into what other Haskellers looked at, I learnt that this type of integer linear programming problem can be solved, in practice, by brute force by binary expansion, pruning and recursion. I wrote up my understanding of the mathematics at https://pilgrem.com/2025/12/30/integer-linear-programming/.