Skip to content

mazharenko/advent-of-code

Repository files navigation

Advent of Code

Here are my solutions for the Advent of Code event.

2️⃣0️⃣2️⃣5️⃣

This year I gave in to the AI hype and tried to build an AI workflow of solving AoC puzzles. Not to delegate writing code to LLMs, but to automate procesess such as:

  1. Downloading an input file
  2. Running an application, feeding the input file to it
  3. Interpreting arbitrary application output
  4. Submitting answers
  5. Updating test cases

Opencode agent equipped with a custom MCP server worked fairly well.

However, using aoc-agent guarantees the fastest submission.

The Superpower extensions received two important updates:

  1. Lines and Lines-based parsers now effectively split a TextSpan (with ExceptSkip instead of ThenIgnore), which allows combining Characters.AnyChar with new lines.
    // line breaks fall into the AnyChar category, but on each line only that line is visible to the parser
    Character.AnyChar.Map();
  2. Similarly, Template parsers effectively split the interpolated string by literals which prevents the injected parses from messing up with literals.
    // the ' ' (space) literal is invisible to the first parser 
    Template.Matching<int[], int>($"{Numerics.Integer32.ManyDelimitedBySpaces()} {{{Numerics.Integer32}}}")

2️⃣0️⃣2️⃣4️⃣

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.

2️⃣0️⃣2️⃣3️⃣

aoc-2023

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:

  1. Go to the site and download the input.
  2. Feed the input to the program.
  3. Copy the result to the clipboard.
  4. Paste it into the browser.
  5. Doh, wrong.
  6. Fix, compile, run, copy, paste.
  7. Doh, "You gave an answer too recently."
  8. Wait.
  9. 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.

2️⃣0️⃣2️⃣2️⃣

AoC-2022

More F# and more visualization in a notebook. Try FParsec to parse input. Try lenses 😱.

2️⃣0️⃣2️⃣1️⃣

AoC-2021

Continue playing with F#. Discovered wonderful .NET Interactive notebooks. Invested into the presentation of the results: mermaid, plotly, canvas.

2️⃣0️⃣2️⃣0️⃣

aoc2020

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.

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages