Skip to content

Commit ce39351

Browse files
committed
[2024] Add comments and fix lints
1 parent 9039c4a commit ce39351

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

aoc_2024/src/day_07.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ impl TestCase {
8686

8787
// Increments the leftmost operation, carrying if it exceeds 1 for
8888
// part a or 2 for part b.
89-
for i in 0..op_count {
90-
ops[i] += 1;
91-
if ops[i] <= (1 + part_b as usize) {
89+
for op in ops.iter_mut() {
90+
*op += 1;
91+
if *op <= (1 + part_b as usize) {
9292
continue 'outer;
9393
}
94-
ops[i] = 0;
94+
*op = 0;
9595
}
9696

9797
return false;

aoc_2024/src/day_08.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ use itertools::Itertools;
99
solution!("Resonant Collinearity", 8);
1010

1111
fn part_a(input: &str) -> Answer {
12+
// Parse the input into a hash table that maps antenna frequencies to positions.
1213
let map = AntennaMap::parse(input);
1314

1415
let mut out = HashSet::new();
1516
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.
1621
for (a, b) in pos.into_iter().tuple_combinations() {
1722
out.extend(
1823
[a + (a - b), b + (b - a)]
@@ -31,6 +36,9 @@ fn part_b(input: &str) -> Answer {
3136
let mut out = HashSet::new();
3237
for (_freq, pos) in map.freqs {
3338
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.
3442
for (mut start, delta) in [(a, a - b), (b, b - a)] {
3543
while map.world.contains(start) {
3644
out.insert(start);

0 commit comments

Comments
 (0)