Here are my solutions for the Advent of Code event.
I had been missing various features of C#. At the same time, I was wondering how well I could handle situations where I had previously relied heavily on specific features of F#. So, this year, I decided to solve the AoC puzzles in C#. And I would catch myself willing to have type aliases / tail recursion / structural equality / whatever, but generally speaking, it was a more comfortable experience, especially since I did not have to push myself to avoid using an imperative style.
Additionally, I was looking forward to improving the parsing process. I tried out Superpower and managed to achieve a concise syntax for some common patterns found in AoC inputs like lines and blocks. It worked fairly well, though dealing with its backtracking was tricky. I also succeeded to construct a parser from a template with use of custom interpolated string handlers, like the following:
Template.Matching<int, int>($"p={Numerics.IntegerInt32},{Numerics.IntegerInt32};") // TextParser<(int, int)>
Some more functions have been added to the aoc-agent, the most significant update is that example inputs and Parse method can now be easily reused across the parts of a single day.
No longer happy with notebooks. Decided to sacrifice visualization at all and focus on a different thing: on optimizing the routine when solving puzzles, namely:
- Go to the site and download the input.
- Feed the input to the program.
- Copy the result to the clipboard.
- Paste it into the browser.
- Doh, wrong.
- Fix, compile, run, copy, paste.
- Doh, "You gave an answer too recently."
- Wait.
- Repeat.
This is how I came up with the idea of aoc-agent — a C# source generator that turns your library with actual algorithms into a self-validating, self-running console application that calculates and submits answers automatically.
Once again, F#. Found Farkle to be much better, still cumbersome and mind-numbing sometimes.
More F# and more visualization in a notebook. Try FParsec to parse input. Try lenses 😱.
Continue playing with F#. Discovered wonderful .NET Interactive notebooks. Invested into the presentation of the results: mermaid, plotly, canvas.
First time taking part in the event. As a C# developer who was reading a lot about F#, wanted to give it a try on "real" tasks. It showed to be quite suitable for many puzzles thanks to immutability and structural comparison out of the box.