day 4 pt 1
This commit is contained in:
62
AdventOfCode/Problems/AOC2025/Day4/PrintingDeparment.cs
Normal file
62
AdventOfCode/Problems/AOC2025/Day4/PrintingDeparment.cs
Normal file
@@ -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<int, int>
|
||||
{
|
||||
private string[] _data = [];
|
||||
private Vec2<int> _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<int>(x, y);
|
||||
if (_data[pos.Y][pos.X] != '@')
|
||||
continue;
|
||||
var n = CountNeighbors(pos);
|
||||
if (n < 4)
|
||||
c++;
|
||||
}
|
||||
}
|
||||
Part1 = c;
|
||||
}
|
||||
|
||||
public int CountNeighbors(Vec2<int> 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<int>(_data[0].Length, _data.Length);
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,4 @@ global using AdventOfCode.Utils;
|
||||
|
||||
|
||||
var runner = new AOCRunner();
|
||||
runner.WithDay(2).RenderInteractiveMenu();
|
||||
runner.RenderInteractiveMenu();
|
||||
|
||||
@@ -24,6 +24,11 @@ public record struct Vec2<T>(T X, T Y) where T : INumber<T>
|
||||
var b = other.Y - this.Y;
|
||||
return (a * a) + (b * b);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({X}, {Y})";
|
||||
}
|
||||
}
|
||||
|
||||
public record struct Vec3<T>(T X, T Y, T Z) where T : INumber<T>
|
||||
@@ -45,4 +50,9 @@ public record struct Vec3<T>(T X, T Y, T Z) where T : INumber<T>
|
||||
var c = other.Z - this.Z;
|
||||
return (a * a) + (b * b) + (c * c);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({X}, {Y}, {Z})";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user