2026/day3: cleanup

This commit is contained in:
ktims committed 2026-12-04 00:16:26 -07:00
1 parent d948c5ae73
commit 464da9d787
1 file changed
+6 -6
+6 -6
View File
@@ -18,15 +18,15 @@ fn part1(input: &Grid<u8>) -> u64 {
for tree in input.find_all(&b'#') { for tree in input.find_all(&b'#') {
for size in 1..(biggest_square - tree.x as usize) { for size in 1..(biggest_square - tree.x as usize) {
if input if input
.get(&(tree + &Coord2d { x: size as i64, y: 0 })) .get(&(tree + Coord2d { x: size as i64, y: 0 }))
.is_some_and(|c| *c == b'#') .is_some_and(|c| *c == b'#')
&& input && input
.get(&(tree + &Coord2d { y: size as i64, x: 0 })) .get(&(tree + Coord2d { y: size as i64, x: 0 }))
.is_some_and(|c| *c == b'#') .is_some_and(|c| *c == b'#')
&& input && input
.get( .get(
&(tree &(tree
+ &Coord2d { + Coord2d {
x: size as i64, x: size as i64,
y: size as i64, y: size as i64,
}), }),
@@ -77,13 +77,13 @@ fn other_two(a: &Coord2d, b: &Coord2d) -> [Coord2d; 2] {
#[aoc(day3, part2, Pairwise)] #[aoc(day3, part2, Pairwise)]
fn part2_pairwise(input: &Grid<u8>) -> u64 { fn part2_pairwise(input: &Grid<u8>) -> u64 {
let trees: Vec<Coord2d> = input.find_all(&b'#').collect(); let trees: Vec<Coord2d> = input.find_all(&b'#').collect();
return trees trees
.iter() .iter()
.tuple_combinations::<(_, _)>() .tuple_combinations::<(_, _)>()
.filter(|(a, b)| (*b - *a).x >= 0 && (*b - *a).y > 0) .filter(|(a, b)| (*b - *a).x >= 0 && (*b - *a).y > 0)
.map(|(a, b)| other_two(&a, &b)) .map(|(a, b)| other_two(a, b))
.filter(|corners| corners.iter().all(|pos| input.get(&pos) == Some(&b'#'))) .filter(|corners| corners.iter().all(|pos| input.get(&pos) == Some(&b'#')))
.count() as u64; .count() as u64
} }
#[aoc(day3, part2, Brute)] #[aoc(day3, part2, Brute)]