Advent of Code 2024 - C#
Objective: Get better at C#.
Dated Jun 25, 2025; last modified on Wed, 25 Jun 2025
Objective: Get better at C#.
| Random Link ¯\_(ツ)_/¯ | ||
| Jan 3, 2026 | » | AoC 2024 Day 14: Restroom Redoubt
2 min; updated Jan 3, 2026
Parsing The input is a list of all robots' current positions \(p = (x, y)\) and velocities \(v = (dx, dy)\), one robot per line, e.g., p=3,6 v=4,-7 p=9,2 v=-1,-2 In \((x, y)\), \(x\) represents the number of tiles away from the left wall, and similarly for \(y\) from the top wall (when viewed from above). The top-left corner of the space is \((0, 0)\). The velocity is given in tiles per second.... |
| Jan 2, 2026 | » | C# Performance Tools
4 min; updated Jan 2, 2026
BenchmarkDotNet Some work projects use BenchmarkDotNet as the .NET library for benchmarking. Getting familiar with it should pay dividends. To run the benchmarks in the Day13ClawContraption class: dotnet run -c Release -- -f '*Day13ClawContraption*' A job describes how to run your benchmark, e.g, ID, environment, run settings. BenchmarkDotNet has a smart algorithm for choosing values like IterationCount, so you typically don’t need to specify those. Sample measurements for the default job:... |
| Dec 7, 2025 | » | AoC 2024 Day 13: Claw Contraption
7 min; updated Dec 7, 2025
Parsing The input is a list of machine configurations, where buttons \(A\) and \(B\) move the claw some distance \(X\) and \(Y\), and the location of the prize is specified. Button A: X+43, Y+68 Button B: X+10, Y+36 Prize: X=4800, Y=6250 Button A: X+63, Y+41 Button B: X+89, Y+18 Prize: X=17648, Y=19276 namespace AoC2024; using Vector = ClawContraption.Vector; using Button = ClawContraption.Button; using MachineConfig = ClawContraption.MachineConfig; using DirectedEdge = ClawContraption.... |
| Nov 30, 2025 | » | AoC 2024 Day 12: Garden Groups
8 min; updated Nov 30, 2025
Parsing Each garden plot grows only a single type of plant indicated by a single letter. This \(4 \times 4\) arrangement includes garden plots growing 5 different types of plants (labelled A, B, C, D, E). AAAA BBCD BBCC EEEC The area of a region is the number of garden plots the region contains. The perimeter of a region is the number of sides of garden plots in the region that do not touch another garden plot in the same region.... |
| Nov 29, 2025 | » | AoC 2024 Day 11: Plutonian Pebbles
4 min; updated Nov 29, 2025
Parsing The stones are in a line, with each stone having a number engraved on it. namespace AoC2024; public static partial class PlutonianPebbles { public static IEnumerable<ulong> ReadStones(string filePath) { var line = File.ReadAllText(filePath).Trim(); return line.Split().Select(ulong.Parse); } } The snippet below contains a subtle bug. The using statement disposes the StreamReader at the end of the scope . This happens before the IEnumerable<ulong> is consumed. However, because ReadLine eagerly reads the content, there is no exception thrown.... |
| Sep 7, 2025 | » | LLM Instructions for Advent of Code Using C#
1 min; updated Sep 7, 2025
The project uses modern C#. The user is an experienced programmer who has been writing C# for a year. Before that, the user mostly wrote imperative object oriented C++ code. Reference concepts from https://learn.microsoft.com/en-us/dotnet/csharp/ where appropriate. Beware of the user writing non idiomatic code, e.g., being too imperative where a declarative or functional programming approach might be better suited. |
| Aug 23, 2025 | » | AoC 2024 Day 08: Resonant Collinearity
4 min; updated Aug 23, 2025
Parsing Each antenna in the map is tuned to a frequency indicated by a single lowercase letter, uppercase letter, or digit. Two antennas with the same frequency create two collinear antinodes on either side where one of the antennas is twice as far away as the other, e.g. .......... ...#...... .......... ....f..... .......... .....f.... .......... ......#... .......... .......... Antinodes can occur at locations that contain other antennas.... |
| Aug 23, 2025 | » | AoC 2024 Day 07: Bridge Repair
6 min; updated Aug 23, 2025
Parsing Each line represents a single equation, e.g., 292: 11 6 16 20. Part One needs to make a decision based on each line independently. Parsing each line into a data structure and yielding that should suffice. using System.Collections.Immutable; using System.Text.RegularExpressions; namespace AoC2024; public partial class BridgeRepair { public static IEnumerable<CalibrationEquation> Parse(string filePath) { using var inputReader = new StreamReader(filePath); string? line; while ((line = inputReader.ReadLine()) != null) { var numbers = InputLineRegex.... |
| Aug 23, 2025 | » | AoC 2024 Day 06: Guard Gallivant
4 min; updated Aug 23, 2025
Parsing The map shows the current position of the guard with ^ (to indicate the guard is facing up from the perspective of the map). Any obstructions - crates, desks, alchemical reactors, etc., are shown as #. ....#..... .........# .......... ..#....... .......#.. .......... .#..^..... ........#. #......... ......#... using System.Collections.Immutable; namespace AoC2024; public partial class GuardGallivant { public enum Orientation { Up, Right, Down, Left } public readonly record struct Coordinate(int R, int C); public readonly record struct Visit(Coordinate Coordinate, Orientation Orientation); public readonly (int RowCount, int ColCount, HashSet<Coordinate> Obstacles) AreaMap; public readonly Visit StartingPosition; public GuardGallivant(string filePath) { using StreamReader inputReader = new(filePath); HashSet<Coordinate> obstacles = []; Visit?... |
| Aug 23, 2025 | » | AoC 2024 Day 05: Print Queue
3 min; updated Aug 23, 2025
Parsing The notation X|Y means that if both page number X and page number Y are to be produced as part of an update, page number X must be printed at some point before page number Y. The input contains page ordering rules (pairs of X|Y) and print queues (e.g., 75, 47, 61, 53, 29). using System.Collections.Immutable; using System.Text.RegularExpressions; namespace AoC2024; public partial class PrintQueue { public readonly Dictionary<int, HashSet<int>> orderingRules = []; public readonly ImmutableList<ImmutableList<int>> printJobs = []; public PrintQueue(string filePath) { using StreamReader inputReader = new(filePath); string?... |
| Aug 23, 2025 | » | AoC 2024 Day 04: Ceres Search
5 min; updated Aug 23, 2025
Problem This word search allows words to be horizontal, vertical, diagonal, written backwards, or even overlapping other words. Here are a few ways XMAS might appear, where irrelevant characters have been replaced with .: ..X... .SAMX. .A..A. XMAS.S .X.... The actual word search will be full of letters instead. For example: MMMSXXMASM MSAMXMSMSA AMXSXMAAMM MSAMASMSMX XMASAMXAMM XXAMMXXAMA SMSMSASXSS SAXAMASAAA MAMMMXMMMM MXMXAXMASX Parsing namespace AoC2024; public partial class CeresSearch { private readonly char[,] grid; public CeresSearch(string filePath) { using StreamReader inputReader = new(filePath); List<char[]> rows = []; string?... |
| Jul 2, 2025 | » | AoC 2024 Day 03: Mull It Over
3 min; updated Jul 2, 2025
Data The computer appears to be trying to run a program, but its memory is corrupted. All of the instructions have been jumbled up! It seems like the goal of the program is just to multiply some numbers. It does that with instructions like mul(X,Y) where X and Y are each 1-3 digit numbers. For instance, mul(44,46) multiplies 44 and 46 to get a result of 2024. However, because the program’s memory has been corrupted, there are also invalid characters that should be ignored, even if they look like a mul instruction.... |
| Jun 30, 2025 | » | AoC 2024 Day 02: Red-Nosed Reports
4 min; updated Jun 30, 2025
Data The unusual data consists of many reports, one report per line. Each report is a list of numbers called levels that are separated by spaces. For example: 7 6 4 2 1 1 2 7 8 9 9 7 6 2 1 1 3 2 4 5 8 6 4 4 1 1 3 6 7 9 To parse: namespace AoC2024; public static partial class RedNosedReports { private static IEnumerable<IEnumerable<int>> GetReports(string filePath) { using StreamReader inputReader = new(filePath); string?... |
| Jun 25, 2025 | » | AoC 2024 Day 01: Historian Hysteria
4 min; updated Jun 25, 2025
Day 1 - Advent of Code 2024: Historian Hysteria. Eric Wastl. adventofcode.com . Accessed Jun 25, 2025. Data There’s just one problem: by holding the two lists up side by side, it quickly becomes clear that the lists aren’t very similar. Maybe you can help The Historians reconcile their lists? For example: 3 4 4 3 2 5 1 3 3 9 3 3 To parse the input:... |
Why doesn’t dchege711/blog@3483b54 add hyperlinks in
.cscode comments?