@@ -9,11 +9,6 @@ function __construct(int $x = 0, int $y = 0) {
9
9
$ this ->y = $ y ;
10
10
}
11
11
12
- static function parse (string $ raw ): Vec2 {
13
- $ split = explode (", " , $ raw );
14
- return new Vec2 (intval ($ split [0 ]), intval ($ split [1 ]));
15
- }
16
-
17
12
function __toString (): string {
18
13
return "$ this ->x , $ this ->y " ;
19
14
}
@@ -50,18 +45,6 @@ function findFrequencyLocations(array $matrix, int $width, int $height): array {
50
45
return $ freqLocs ;
51
46
}
52
47
53
- function findAntennas (array $ freqLocs , int $ width , int $ height ): array {
54
- $ antennas = [];
55
-
56
- foreach ($ freqLocs as $ freq => $ locs ) {
57
- foreach ($ locs as $ loc ) {
58
- $ antennas ["$ loc " ] = true ;
59
- }
60
- }
61
-
62
- return $ antennas ;
63
- }
64
-
65
48
function findAntinodes (array $ freqLocs , int $ width , int $ height , bool $ includeStart = true , int $ maxRepeats = PHP_INT_MAX ): array {
66
49
$ antinodes = [];
67
50
@@ -102,23 +85,9 @@ function findAntinodes(array $freqLocs, int $width, int $height, bool $includeSt
102
85
$ width = strlen ($ matrix [0 ]);
103
86
104
87
$ freqLocs = findFrequencyLocations ($ matrix , $ width , $ height );
105
- $ antennas = findAntennas ($ freqLocs , $ width , $ height );
106
-
107
- $ antinodes1 = findAntinodes ($ freqLocs , $ width , $ height , false , 1 );
108
- $ antinodes2 = findAntinodes ($ freqLocs , $ width , $ height );
109
-
110
- // Draw the antinode pattern for fun and profit
111
- foreach (array_keys ($ antinodes2 ) as $ rawAntinode ) {
112
- $ antinode = Vec2::parse ($ rawAntinode );
113
- $ matrix [$ antinode ->y ][$ antinode ->x ] = '# ' ;
114
- }
115
-
116
- foreach ($ matrix as $ line ) {
117
- echo "$ line " . PHP_EOL ;
118
- }
119
88
120
- $ part1 = count ($ antinodes1 );
89
+ $ part1 = count (findAntinodes ( $ freqLocs , $ width , $ height , false , 1 ) );
121
90
echo "Part 1: $ part1 " . PHP_EOL ;
122
91
123
- $ part2 = count ($ antinodes2 );
92
+ $ part2 = count (findAntinodes ( $ freqLocs , $ width , $ height ) );
124
93
echo "Part 2: $ part2 " . PHP_EOL ;
0 commit comments