File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
AdventOfCode/Solutions/Year2024 Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ protected override object SolvePartOne()
25
25
if ( ! checkedChars . Add ( kvp . Value ) ) continue ;
26
26
27
27
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 ) )
30
30
{
31
31
var n = c . First ( ) . Key ;
32
32
var m = c . Last ( ) . Key ;
@@ -48,14 +48,12 @@ protected override object SolvePartOne()
48
48
protected override object SolvePartTwo ( )
49
49
{
50
50
HashSet < char > checkedChars = new ( ) ;
51
- antinodes . Clear ( ) ;
52
- foreach ( var c in map . Keys ) antinodes . Add ( c ) ;
53
51
foreach ( var kvp in map )
54
52
{
55
53
if ( ! checkedChars . Add ( kvp . Value ) ) continue ;
56
54
57
55
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.
59
57
foreach ( var c in sameNodes . Combinations ( 2 ) )
60
58
{
61
59
var n = c . First ( ) . Key ;
@@ -64,6 +62,9 @@ protected override object SolvePartTwo()
64
62
var dX = n . x - m . x ;
65
63
var dY = n . y - m . y ;
66
64
65
+ antinodes . Add ( n ) ;
66
+ antinodes . Add ( m ) ;
67
+
67
68
Coordinate2D p1 = n + ( dX , dY ) ;
68
69
Coordinate2D p2 = m - ( dX , dY ) ;
69
70
You can’t perform that action at this time.
0 commit comments