From 9f1a2d2300e0220a0e3f546e1f2da4621b643a6b Mon Sep 17 00:00:00 2001 From: Amatsugu Date: Thu, 4 Dec 2025 12:58:34 -0500 Subject: [PATCH] day 4 pt 1 --- .../AOC2025/Day4/PrintingDeparment.cs | 62 +++++++++++++++++++ AdventOfCode/Program.cs | 2 +- AdventOfCode/Utils/Models/Common.cs | 10 +++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 AdventOfCode/Problems/AOC2025/Day4/PrintingDeparment.cs diff --git a/AdventOfCode/Problems/AOC2025/Day4/PrintingDeparment.cs b/AdventOfCode/Problems/AOC2025/Day4/PrintingDeparment.cs new file mode 100644 index 0000000..18a56de --- /dev/null +++ b/AdventOfCode/Problems/AOC2025/Day4/PrintingDeparment.cs @@ -0,0 +1,62 @@ +using AdventOfCode.Utils.Models; + +using System; +using System.Collections.Generic; +using System.Text; + +namespace AdventOfCode.Problems.AOC2025.Day4; +[ProblemInfo(2025, 4, "Printing Department")] +internal class PrintingDeparment: Problem +{ + private string[] _data = []; + private Vec2 _size; + + public override void CalculatePart1() + { + var c = 0; + for (int y = 0; y < _size.Y; y++) + { + for (int x = 0; x < _size.X; x++) + { + var pos = new Vec2(x, y); + if (_data[pos.Y][pos.X] != '@') + continue; + var n = CountNeighbors(pos); + if (n < 4) + c++; + } + } + Part1 = c; + } + + public int CountNeighbors(Vec2 pos) + { + var c = 0; + for (int y = pos.Y-1; y <= pos.Y + 1; y++) + { + if (y < 0 || y >= _size.Y) + continue; + for (int x = pos.X - 1; x <= pos.X + 1; x++) + { + if (x < 0 || x >= _size.X) + continue; + if (pos.X == x && pos.Y == y) + continue; + if (_data[y][x] == '@') + c++; + } + } + return c; + } + + public override void CalculatePart2() + { + throw new NotImplementedException(); + } + + public override void LoadInput() + { + _data = ReadInputLines("input.txt"); + _size = new Vec2(_data[0].Length, _data.Length); + } +} diff --git a/AdventOfCode/Program.cs b/AdventOfCode/Program.cs index b6b2c75..248aa77 100644 --- a/AdventOfCode/Program.cs +++ b/AdventOfCode/Program.cs @@ -4,4 +4,4 @@ global using AdventOfCode.Utils; var runner = new AOCRunner(); -runner.WithDay(2).RenderInteractiveMenu(); +runner.RenderInteractiveMenu(); diff --git a/AdventOfCode/Utils/Models/Common.cs b/AdventOfCode/Utils/Models/Common.cs index 3107a08..748b78c 100644 --- a/AdventOfCode/Utils/Models/Common.cs +++ b/AdventOfCode/Utils/Models/Common.cs @@ -24,6 +24,11 @@ public record struct Vec2(T X, T Y) where T : INumber var b = other.Y - this.Y; return (a * a) + (b * b); } + + public override string ToString() + { + return $"({X}, {Y})"; + } } public record struct Vec3(T X, T Y, T Z) where T : INumber @@ -45,4 +50,9 @@ public record struct Vec3(T X, T Y, T Z) where T : INumber var c = other.Z - this.Z; return (a * a) + (b * b) + (c * c); } + + public override string ToString() + { + return $"({X}, {Y}, {Z})"; + } } \ No newline at end of file