@@ -9,10 +9,15 @@ use itertools::Itertools;
9
9
solution ! ( "Resonant Collinearity" , 8 ) ;
10
10
11
11
fn part_a ( input : & str ) -> Answer {
12
+ // Parse the input into a hash table that maps antenna frequencies to positions.
12
13
let map = AntennaMap :: parse ( input) ;
13
14
14
15
let mut out = HashSet :: new ( ) ;
15
16
for ( _freq, pos) in map. freqs {
17
+ // Because a line is defined by two points, we find all point
18
+ // combinations with two points. To get the two antinode points, we add
19
+ // the difference between both points to the first point and subtract
20
+ // the difference from the second.
16
21
for ( a, b) in pos. into_iter ( ) . tuple_combinations ( ) {
17
22
out. extend (
18
23
[ a + ( a - b) , b + ( b - a) ]
@@ -31,6 +36,9 @@ fn part_b(input: &str) -> Answer {
31
36
let mut out = HashSet :: new ( ) ;
32
37
for ( _freq, pos) in map. freqs {
33
38
for ( a, b) in pos. into_iter ( ) . tuple_combinations ( ) {
39
+ // For part be we just need to keep adding / subtracting the
40
+ // diffract between the two points to the starting position until
41
+ // the result is out of bounds.
34
42
for ( mut start, delta) in [ ( a, a - b) , ( b, b - a) ] {
35
43
while map. world . contains ( start) {
36
44
out. insert ( start) ;
0 commit comments