Skip to content

Commit 31c4baa

Browse files
committed
Modify 2024 Day 8 to actually match the problem statement
1 parent 393e55e commit 31c4baa

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

AdventOfCode/Solutions/Year2024/Day08-Solution.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ protected override object SolvePartOne()
2525
if (!checkedChars.Add(kvp.Value)) continue;
2626

2727
var sameNodes = map.Where(a => a.Value == kvp.Value);
28-
29-
foreach(var c in sameNodes.Combinations(2))
28+
if (sameNodes.Count() == 1) continue; //In the off chance it's the only antenna of it's type.
29+
foreach (var c in sameNodes.Combinations(2))
3030
{
3131
var n = c.First().Key;
3232
var m = c.Last().Key;
@@ -48,14 +48,12 @@ protected override object SolvePartOne()
4848
protected override object SolvePartTwo()
4949
{
5050
HashSet<char> checkedChars = new();
51-
antinodes.Clear();
52-
foreach (var c in map.Keys) antinodes.Add(c);
5351
foreach (var kvp in map)
5452
{
5553
if (!checkedChars.Add(kvp.Value)) continue;
5654

5755
var sameNodes = map.Where(a => a.Value == kvp.Value);
58-
56+
if (sameNodes.Count() == 1) continue; //In the off chance it's the only antenna of it's type.
5957
foreach (var c in sameNodes.Combinations(2))
6058
{
6159
var n = c.First().Key;
@@ -64,6 +62,9 @@ protected override object SolvePartTwo()
6462
var dX = n.x - m.x;
6563
var dY = n.y - m.y;
6664

65+
antinodes.Add(n);
66+
antinodes.Add(m);
67+
6768
Coordinate2D p1 = n + (dX, dY);
6869
Coordinate2D p2 = m - (dX, dY);
6970

0 commit comments

Comments
 (0)