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 ¯\_(ツ)_/¯ | ||
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
.cs
code comments?