diff --git a/2025/07.rs b/2025/07.rs new file mode 100644 index 0000000..e76ee4b --- /dev/null +++ b/2025/07.rs @@ -0,0 +1,67 @@ +---cargo +--- + +static CONTENT: &'static str = include_str!("./inputs/07_1.txt"); + +#[derive(Debug, PartialEq)] +enum Cell { + Empty, + Split, + Sourc, + TBeam, +} + +fn main() { + let mut grid: Vec<_> = CONTENT.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).map(|l| { + l.chars().map(|c| match c { + '.' => Cell::Empty, + 'S' => Cell::Sourc, + '^' => Cell::Split, + other => unreachable!("Unexpected Input {:?}", other), + }).collect::>() + }).collect(); + + println!("Grid: {:?}", grid); + + // (x, y) + let source = grid.iter().enumerate().flat_map(|(y, row)| core::iter::repeat(y).zip(row.iter().enumerate()).map(|(y, (x, c))| (y, x, c))).find_map(|(y, x, c)| (c == &Cell::Sourc).then_some((x, y))).unwrap(); + println!("Source {:?}", source); + + let mut splits = 0; + + let mut queue: Vec<(usize, usize)> = vec![(source.0, source.1+1)]; + while let Some((x, mut y)) = queue.pop() { + if grid[y][x] != Cell::Empty { + continue; + } + + while grid.get(y).map(|r| &r[x]) == Some(&Cell::Empty) { + // println!("({}, {})", x, y); + + grid[y][x] = Cell::TBeam; + y += 1; + } + + match grid.get(y).map(|r| &r[x]) { + None => {} + Some(Cell::Empty) => unreachable!(), + Some(Cell::Sourc) => unreachable!(), + Some(Cell::Split) => { + // println!("Split"); + splits += 1; + + if let Some(nx) = x.checked_sub(1) { + queue.push((nx, y)); + } + if x+1 < grid[y].len() { + queue.push((x+1, y)); + } + } + Some(Cell::TBeam) => { + println!("Beam"); + } + }; + } + + println!("Splits: {:?}", splits); +} diff --git a/2025/inputs/07_1.txt b/2025/inputs/07_1.txt new file mode 100644 index 0000000..1de5cbd --- /dev/null +++ b/2025/inputs/07_1.txt @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^.^.^.................................................................... +............................................................................................................................................. +...................................................................^.^.^.^................................................................... +............................................................................................................................................. +..................................................................^.^.^.^.^.................................................................. +............................................................................................................................................. +.................................................................^...^...^.^................................................................. +............................................................................................................................................. +................................................................^.^.^...^...^................................................................ +............................................................................................................................................. +...............................................................^.....^...^...^............................................................... +............................................................................................................................................. +..............................................................^...^.^.....^.^.^.............................................................. +............................................................................................................................................. +.............................................................^.^.^...^.......^.^............................................................. +............................................................................................................................................. +............................................................^...^.^.....^.^.^.^.^............................................................ +............................................................................................................................................. +...........................................................^.^.....^.^.....^.^.^.^........................................................... +............................................................................................................................................. +..........................................................^.^...^.^...^.^.^.^.^...^.......................................................... +............................................................................................................................................. +.........................................................^...^.^.....^.^.....^.^.^.^......................................................... +............................................................................................................................................. +........................................................^.^.^.......^.^.^.^.^.^.^.^.^........................................................ +............................................................................................................................................. +.......................................................^.^.^.....^...^.....^.^.^...^.^....................................................... +............................................................................................................................................. +......................................................^...^.^.^.^.^.^.^.......^.^.^.^.^...................................................... +............................................................................................................................................. +.....................................................^.^.^...^...^...^.....^.......^.^.^..................................................... +............................................................................................................................................. +....................................................^...^...^.^.^...^.^.^.^.^...^.^.^...^.................................................... +............................................................................................................................................. +...................................................^...^...^.^...^.^...^...^...........^.^................................................... +............................................................................................................................................. +..................................................^.^.^.^.^.......^.^.^.^.^...^.^...^.^.^.^.................................................. +............................................................................................................................................. +.................................................^.^.^.^.....^.^.^.......^.^.......^.^.^.^.^................................................. +............................................................................................................................................. +................................................^...^.^.^.^.^.^.^.^.^.^.^.....^...^.^.^...^.^................................................ +............................................................................................................................................. +...............................................^.^...^...^.^.^.^...^.^.^.^...^.^.^...^.^.^...^............................................... +............................................................................................................................................. +..............................................^...^.^...^.^.^.....^.^.^.^...^.^.^.^.^...^.....^.............................................. +............................................................................................................................................. +.............................................^.....^...^...^.^...^.....^.^.^.^...^.......^.^...^............................................. +............................................................................................................................................. +............................................^.^...^.^.^.^.^.^.^...^.^.^.^.^...^.....^.^.^.^...^.^............................................ +............................................................................................................................................. +...........................................^.^.^.^.^.^.......^.^...^.^.^.....^.^.^.......^...^.^.^........................................... +............................................................................................................................................. +..........................................^...^.^.^.^.^.^.^...^.^.....^.^.^.^.....^.^.^.^...^.^.^.^.......................................... +............................................................................................................................................. +.........................................^.^...^...^.....^.^...^.^.^.^...^.......^...^...^.^.....^.^......................................... +............................................................................................................................................. +........................................^.^...^.^.^.^...........^.^...^.^.....^...^.^.....^.^...^.^.^........................................ +............................................................................................................................................. +.......................................^.^...^.^.^.^.^...^.^.^...^.^.....^.......^.^.^.^.....^.^.....^....................................... +............................................................................................................................................. +......................................^...^.^.^...^.......^...^.^.^...^...^.^.^...^...^.....^...^.^.^.^...................................... +............................................................................................................................................. +.....................................^.^.^.^.......^.^...^.^.^.^.^...^.^.....^.^.^.^...^.^.^.^...^.^.^.^..................................... +............................................................................................................................................. +....................................^...^...^.^.^.^.^.....^.^.^.^...^...^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.................................... +............................................................................................................................................. +...................................^.....^.^...^...^.^...^.^...^.^.^.^.......^.^.^.^.^.^.^.^...^.^.^.^.^.^................................... +............................................................................................................................................. +..................................^.^.^...^.^.^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.^...^...^...^.^.^.^.^.................................. +............................................................................................................................................. +.................................^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.....^.^...^...^.^...^.^.^.^...^................................. +............................................................................................................................................. +................................^.^.^.....^.^.....^...^.^.^.^.^.^...^...^.^...^.....^.^.^.^.^.^.^.^.^...^.^.^................................ +............................................................................................................................................. +...............................^.^.^.^.....^.^.....^.^.....^.^.....^.....^.^...^.^.....^.^.....^...^.^.^.^.^.^............................... +............................................................................................................................................. +..............................^.^.^.^...^.....^.^.^.........^.^.......^...^...^...^.^.^.^.......^.^.^.^.^.^.^.^.............................. +............................................................................................................................................. +.............................^.^.^.....^.^.^.....^.^.^.^...^.....^.^.^.^.^...^.^.^.^.^.^.^...^.^.^.^.......^.^.^............................. +............................................................................................................................................. +............................^...^.^.^.^.^...^.^.....^.^...^...^.^.....^.^...^.^.^.^...^.^.^.^.^.^...^.^...^.^.^.^............................ +............................................................................................................................................. +...........................^.....^.^.^.^.^...^.^.^.^.........^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^........................... +............................................................................................................................................. +..........................^.^.......^.^.^...^.^.^.^.^...^.^.^...^.^...^.^.^.^...^...^...^.^...^...^.^.^.^.^.^.....^.......................... +............................................................................................................................................. +.........................^.^.^...^.^.^...^.^...^.^.^.^.^.^.^.......^.^.^.^...^.^.....^.....^.^.^.^...^.....^.^.^...^......................... +............................................................................................................................................. +........................^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^...^.....^...^.^.^.^.^.^.^.....^.^...^.^.^.^........................ +............................................................................................................................................. +.......................^.^.^.^...^...^...^.^.^...^.^.^.^.^.....^.^.......^.^...^.^...^.^.^...^...^.^.^...^.^.....^...^....................... +............................................................................................................................................. +......................^.^.........^.....^.^.....^...^...^...^.^.^.^.^.......^.^...^...^.^.^.^.......^.^...^.^.^...^.^.^...................... +............................................................................................................................................. +.....................^.^.^...^...^.^...^.^.^...^...^.^.^.^.^.^.^...^...^.^.^.^.....^.^.^...^.^.....^...^...^...^.^.^.^.^..................... +............................................................................................................................................. +....................^.^.^...^.^.^...^.^.^.....^.......^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.....^.^.^.^.^.^...^.^.^...^.^.^.^.................... +............................................................................................................................................. +...................^.....^.^...^.^...^.^...^.^.....^...^.^.^.......^.^.^.^.^.^.^.^.^...^.^.^.^.^...^.^.^.^...^.^.^.^.^...^................... +............................................................................................................................................. +..................^.^.^.^.^.^.^...^.^.^.^.....^.^.^.^.^.^.^...^.^...^...^...^.^.^.^.......^.^.^.....^.^...^.^.^...^.^...^.^.................. +............................................................................................................................................. +.................^...^.^.^.^.^...^.......^.^.^.....^.^...^...^.^.^...^.^...^...^...^...^.^.^...^...^.^...^.^.^.^.^.^.^.^.^.^................. +............................................................................................................................................. +................^.^...^...^.^...^.^.....^.^.^.^.^.^.......^.^.^...^.^.^.^.^.^.^.^.^...........^.^.^.....^.....^.^.^.^.^.^...^................ +............................................................................................................................................. +...............^.^.^...^.^.^.^.^.^.........^.^.^.^.^.......^...^.....^...^.^...^.....^...^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^............... +............................................................................................................................................. +..............^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^...^.^...^.......^.^...^.^.^...^.....^.^.^...^.^.^.^.^...^.^.^.^.^...^.^.............. +............................................................................................................................................. +.............^.^.^.^.^...^.^.^.......^.^.^...^.^.^.^...^.^.^.^...^.....^.^.......^.^.........^.^.^.^.^.....^.^.^.^.^.^.^...^.^.^............. +............................................................................................................................................. +............^...^.^...^.^.^.^.^.^...........^.^.^.^.^.^.^.^.^.^.....^.^.^.^...^.....^.^.......^...^.^...^.....^.^.^...^.^.^...^.^............ +............................................................................................................................................. +...........^.^.^.^.^.^.^.....^.^...^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.....^.^.^.^.^.^...^...^.^.^.^...^.^.^.^...^.^.^.^...^.^.^.^.^.^........... +............................................................................................................................................. +..........^...^.^.^.^.^.^...^...^.^...^.^.^.^.^.^...^.^...^.^.^.^.^.^.^.^...^.^.^...^.^.^...^.^.^.^...^...^.^.^.^.^.^...^.^.^.^.^.^.......... +............................................................................................................................................. +.........^...^.^...^.....^.^.^...^.......^.^.....^.......^...^...^...^.^.^.^.^.^.^.....^.^.^.....^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^......... +............................................................................................................................................. +........^.^...........^...^.......^.^...^.^.^...^.^.^.^...^.^...^.^.^.......^...^.^.^.^.^.^.^.^.^.^.....^...^...^.....^.^.^.^.^.^.^.^........ +............................................................................................................................................. +.......^...^...^.^.^...^.^.^.....^.^...^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^...^.^...^...^.^.^...^.^.^.^.^.....^...^.^.....^.^....... +............................................................................................................................................. +......^...^.^...^...^...^.^.^...^.^.^.^...^...^.^.^...^.^.....^.^.^...^.....^...^.^...^.......^.^...^.^.....^...^.^.^.^.^.^.^.^.^.^...^...... +............................................................................................................................................. +.....^.^.^.^...^.^.....^.^...^.^.......^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^...^...^.^..... +............................................................................................................................................. +....^...^...^.^.^.^...^.^.^...^.^.....^.^.^...^.^.^.^...^.^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.......^.^.^.^.^.....^.^.^.^...^.^.^.^.^...^.^.... +............................................................................................................................................. +...^.^...^...^.......^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^...^...^.^...^...^.^.^.^.^.^.^.^.^.....^...^.^...^.^...^.^.^.^...^... +............................................................................................................................................. +..^.^.........^.^.^.^.^.^.^.^.^.^...^.......^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...........^.....^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.. +............................................................................................................................................. +.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.....^.^...^.^.^.^.^.^...^.^...^.^.^.^.^...^...^...^...^.^.^.^.^.^...^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.....^. +............................................................................................................................................. diff --git a/2025/inputs/07_example.txt b/2025/inputs/07_example.txt new file mode 100644 index 0000000..57a2466 --- /dev/null +++ b/2025/inputs/07_example.txt @@ -0,0 +1,16 @@ +.......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +...............