From 0ea78d396b1ad1293f2f96fd48ab479d4a24e06a Mon Sep 17 00:00:00 2001 From: Parnic Date: Wed, 25 Dec 2024 08:15:08 -0600 Subject: [PATCH] Day 25 Merry Christmas! --- src/25.cs | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/25.cs diff --git a/src/25.cs b/src/25.cs new file mode 100644 index 0000000..32b2527 --- /dev/null +++ b/src/25.cs @@ -0,0 +1,104 @@ +namespace aoc2024; + +internal class Day25 : Day +{ + private List> locks = []; + private List> keys = []; + + internal override void Parse() + { + var lines = Util.Parsing.ReadAllLines($"{GetDay()}").ToList(); + var type = -1; + var grid = new bool[5, 5]; + int count = 0; + bool checking = false; + foreach (var line in lines) + { + if (line.Length == 0) + { + type = -1; + count = 0; + continue; + } + + if (type == -1) + { + type = line == "#####" ? 0 : 1; + } + + if (line is "#####" or "....." && (!checking || count == 5)) + { + checking = true; + + if (count == 5) + { + List arrangement = []; + for (int x = 0; x < grid.GetLength(1); x++) + { + int height = 0; + for (int y = 0; y < grid.GetLength(0); y++) + { + if (grid[x, y]) + { + height++; + } + } + + arrangement.Add(height); + } + + if (type == 0) + { + locks.Add(arrangement); + } + else + { + keys.Add(arrangement); + } + + checking = false; + } + continue; + } + + for (int i = 0; i < line.Length; i++) + { + grid[i, count] = line[i] == '#'; + } + + count++; + } + } + + internal override string Part1() + { + long matches = 0; + foreach (var key in keys) + { + foreach (var lck in locks) + { + bool match = true; + for (int i = 0; i < 5; i++) + { + if (key[i] + lck[i] > 5) + { + match = false; + break; + } + } + + if (match) + { + matches++; + } + } + } + + return $"Lock/key fits: <+white>{matches}"; + } + + internal override string Part2() + { + return "Merry Christmas!"; + } +}