From 30644bcbfc61a59071347270cf0620a0c66c7fb3 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Sun, 7 Dec 2025 00:27:23 -0800 Subject: [PATCH] day7: remember to use some convenience functions from my grid --- src/day7.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/day7.rs b/src/day7.rs index c25fefd..982ce4c 100644 --- a/src/day7.rs +++ b/src/day7.rs @@ -1,5 +1,5 @@ use aoc_runner_derive::{aoc, aoc_generator}; -use grid::{AsCoord2d, Grid}; +use grid::{Coord2d, Grid}; use itertools::Itertools; use std::str::FromStr; @@ -8,13 +8,11 @@ fn parse(input: &str) -> Grid { Grid::from_str(input).unwrap() } -fn emit_beams(grid: &mut Grid, pos: impl AsCoord2d) -> u64 { +fn emit_beams(grid: &mut Grid, pos: Coord2d) -> u64 { match grid.set(&pos, b'|') { None | Some(b'|') => 0, - Some(b'.') | Some(b'S') => emit_beams(grid, (pos.x(), pos.y() + 1)), - Some(b'^') => { - 1 + emit_beams(grid, (pos.x() - 1, pos.y())) + emit_beams(grid, (pos.x() + 1, pos.y())) - } + Some(b'.') | Some(b'S') => emit_beams(grid, pos + &(0, 1)), + Some(b'^') => 1 + emit_beams(grid, pos + &(-1, 0)) + emit_beams(grid, pos + &(1, 0)), _ => panic!(), } } @@ -39,12 +37,12 @@ fn part2(input: &Grid) -> u64 { None => panic!("How did we end up outside the grid?"), // if our current position is a caret, add that count to our neighbours Some(b'^') => { - grid.set(&(x - 1, y), grid.get(&(x - 1, y)).unwrap() + n); - grid.set(&(x + 1, y), grid.get(&(x + 1, y)).unwrap() + n); + grid.increment(&(x - 1, y), n); + grid.increment(&(x + 1, y), n); } // if our current position is a . add that count here Some(b'.') => { - grid.set(&(x, y), grid.get(&(x, y)).unwrap() + n); + grid.increment(&(x, y), n); } _ => panic!(), }