Implement 2025 - Day 7 - Part 1

This commit is contained in:
Lol3rrr
2026-01-09 17:56:31 +01:00
parent 5f792c2ffa
commit 947b9cafca
3 changed files with 225 additions and 0 deletions

67
2025/07.rs Normal file
View File

@@ -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::<Vec<_>>()
}).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);
}

142
2025/inputs/07_1.txt Normal file
View File

@@ -0,0 +1,142 @@
......................................................................S......................................................................
.............................................................................................................................................
......................................................................^......................................................................
.............................................................................................................................................
.....................................................................^.^.....................................................................
.............................................................................................................................................
....................................................................^.^.^....................................................................
.............................................................................................................................................
...................................................................^.^.^.^...................................................................
.............................................................................................................................................
..................................................................^.^.^.^.^..................................................................
.............................................................................................................................................
.................................................................^...^...^.^.................................................................
.............................................................................................................................................
................................................................^.^.^...^...^................................................................
.............................................................................................................................................
...............................................................^.....^...^...^...............................................................
.............................................................................................................................................
..............................................................^...^.^.....^.^.^..............................................................
.............................................................................................................................................
.............................................................^.^.^...^.......^.^.............................................................
.............................................................................................................................................
............................................................^...^.^.....^.^.^.^.^............................................................
.............................................................................................................................................
...........................................................^.^.....^.^.....^.^.^.^...........................................................
.............................................................................................................................................
..........................................................^.^...^.^...^.^.^.^.^...^..........................................................
.............................................................................................................................................
.........................................................^...^.^.....^.^.....^.^.^.^.........................................................
.............................................................................................................................................
........................................................^.^.^.......^.^.^.^.^.^.^.^.^........................................................
.............................................................................................................................................
.......................................................^.^.^.....^...^.....^.^.^...^.^.......................................................
.............................................................................................................................................
......................................................^...^.^.^.^.^.^.^.......^.^.^.^.^......................................................
.............................................................................................................................................
.....................................................^.^.^...^...^...^.....^.......^.^.^.....................................................
.............................................................................................................................................
....................................................^...^...^.^.^...^.^.^.^.^...^.^.^...^....................................................
.............................................................................................................................................
...................................................^...^...^.^...^.^...^...^...........^.^...................................................
.............................................................................................................................................
..................................................^.^.^.^.^.......^.^.^.^.^...^.^...^.^.^.^..................................................
.............................................................................................................................................
.................................................^.^.^.^.....^.^.^.......^.^.......^.^.^.^.^.................................................
.............................................................................................................................................
................................................^...^.^.^.^.^.^.^.^.^.^.^.....^...^.^.^...^.^................................................
.............................................................................................................................................
...............................................^.^...^...^.^.^.^...^.^.^.^...^.^.^...^.^.^...^...............................................
.............................................................................................................................................
..............................................^...^.^...^.^.^.....^.^.^.^...^.^.^.^.^...^.....^..............................................
.............................................................................................................................................
.............................................^.....^...^...^.^...^.....^.^.^.^...^.......^.^...^.............................................
.............................................................................................................................................
............................................^.^...^.^.^.^.^.^.^...^.^.^.^.^...^.....^.^.^.^...^.^............................................
.............................................................................................................................................
...........................................^.^.^.^.^.^.......^.^...^.^.^.....^.^.^.......^...^.^.^...........................................
.............................................................................................................................................
..........................................^...^.^.^.^.^.^.^...^.^.....^.^.^.^.....^.^.^.^...^.^.^.^..........................................
.............................................................................................................................................
.........................................^.^...^...^.....^.^...^.^.^.^...^.......^...^...^.^.....^.^.........................................
.............................................................................................................................................
........................................^.^...^.^.^.^...........^.^...^.^.....^...^.^.....^.^...^.^.^........................................
.............................................................................................................................................
.......................................^.^...^.^.^.^.^...^.^.^...^.^.....^.......^.^.^.^.....^.^.....^.......................................
.............................................................................................................................................
......................................^...^.^.^...^.......^...^.^.^...^...^.^.^...^...^.....^...^.^.^.^......................................
.............................................................................................................................................
.....................................^.^.^.^.......^.^...^.^.^.^.^...^.^.....^.^.^.^...^.^.^.^...^.^.^.^.....................................
.............................................................................................................................................
....................................^...^...^.^.^.^.^.....^.^.^.^...^...^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^....................................
.............................................................................................................................................
...................................^.....^.^...^...^.^...^.^...^.^.^.^.......^.^.^.^.^.^.^.^...^.^.^.^.^.^...................................
.............................................................................................................................................
..................................^.^.^...^.^.^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.^...^...^...^.^.^.^.^..................................
.............................................................................................................................................
.................................^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.....^.^...^...^.^...^.^.^.^...^.................................
.............................................................................................................................................
................................^.^.^.....^.^.....^...^.^.^.^.^.^...^...^.^...^.....^.^.^.^.^.^.^.^.^...^.^.^................................
.............................................................................................................................................
...............................^.^.^.^.....^.^.....^.^.....^.^.....^.....^.^...^.^.....^.^.....^...^.^.^.^.^.^...............................
.............................................................................................................................................
..............................^.^.^.^...^.....^.^.^.........^.^.......^...^...^...^.^.^.^.......^.^.^.^.^.^.^.^..............................
.............................................................................................................................................
.............................^.^.^.....^.^.^.....^.^.^.^...^.....^.^.^.^.^...^.^.^.^.^.^.^...^.^.^.^.......^.^.^.............................
.............................................................................................................................................
............................^...^.^.^.^.^...^.^.....^.^...^...^.^.....^.^...^.^.^.^...^.^.^.^.^.^...^.^...^.^.^.^............................
.............................................................................................................................................
...........................^.....^.^.^.^.^...^.^.^.^.........^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^...........................
.............................................................................................................................................
..........................^.^.......^.^.^...^.^.^.^.^...^.^.^...^.^...^.^.^.^...^...^...^.^...^...^.^.^.^.^.^.....^..........................
.............................................................................................................................................
.........................^.^.^...^.^.^...^.^...^.^.^.^.^.^.^.......^.^.^.^...^.^.....^.....^.^.^.^...^.....^.^.^...^.........................
.............................................................................................................................................
........................^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^...^.....^...^.^.^.^.^.^.^.....^.^...^.^.^.^........................
.............................................................................................................................................
.......................^.^.^.^...^...^...^.^.^...^.^.^.^.^.....^.^.......^.^...^.^...^.^.^...^...^.^.^...^.^.....^...^.......................
.............................................................................................................................................
......................^.^.........^.....^.^.....^...^...^...^.^.^.^.^.......^.^...^...^.^.^.^.......^.^...^.^.^...^.^.^......................
.............................................................................................................................................
.....................^.^.^...^...^.^...^.^.^...^...^.^.^.^.^.^.^...^...^.^.^.^.....^.^.^...^.^.....^...^...^...^.^.^.^.^.....................
.............................................................................................................................................
....................^.^.^...^.^.^...^.^.^.....^.......^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.....^.^.^.^.^.^...^.^.^...^.^.^.^....................
.............................................................................................................................................
...................^.....^.^...^.^...^.^...^.^.....^...^.^.^.......^.^.^.^.^.^.^.^.^...^.^.^.^.^...^.^.^.^...^.^.^.^.^...^...................
.............................................................................................................................................
..................^.^.^.^.^.^.^...^.^.^.^.....^.^.^.^.^.^.^...^.^...^...^...^.^.^.^.......^.^.^.....^.^...^.^.^...^.^...^.^..................
.............................................................................................................................................
.................^...^.^.^.^.^...^.......^.^.^.....^.^...^...^.^.^...^.^...^...^...^...^.^.^...^...^.^...^.^.^.^.^.^.^.^.^.^.................
.............................................................................................................................................
................^.^...^...^.^...^.^.....^.^.^.^.^.^.......^.^.^...^.^.^.^.^.^.^.^.^...........^.^.^.....^.....^.^.^.^.^.^...^................
.............................................................................................................................................
...............^.^.^...^.^.^.^.^.^.........^.^.^.^.^.......^...^.....^...^.^...^.....^...^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...............
.............................................................................................................................................
..............^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^...^.^...^.......^.^...^.^.^...^.....^.^.^...^.^.^.^.^...^.^.^.^.^...^.^..............
.............................................................................................................................................
.............^.^.^.^.^...^.^.^.......^.^.^...^.^.^.^...^.^.^.^...^.....^.^.......^.^.........^.^.^.^.^.....^.^.^.^.^.^.^...^.^.^.............
.............................................................................................................................................
............^...^.^...^.^.^.^.^.^...........^.^.^.^.^.^.^.^.^.^.....^.^.^.^...^.....^.^.......^...^.^...^.....^.^.^...^.^.^...^.^............
.............................................................................................................................................
...........^.^.^.^.^.^.^.....^.^...^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.....^.^.^.^.^.^...^...^.^.^.^...^.^.^.^...^.^.^.^...^.^.^.^.^.^...........
.............................................................................................................................................
..........^...^.^.^.^.^.^...^...^.^...^.^.^.^.^.^...^.^...^.^.^.^.^.^.^.^...^.^.^...^.^.^...^.^.^.^...^...^.^.^.^.^.^...^.^.^.^.^.^..........
.............................................................................................................................................
.........^...^.^...^.....^.^.^...^.......^.^.....^.......^...^...^...^.^.^.^.^.^.^.....^.^.^.....^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.........
.............................................................................................................................................
........^.^...........^...^.......^.^...^.^.^...^.^.^.^...^.^...^.^.^.......^...^.^.^.^.^.^.^.^.^.^.....^...^...^.....^.^.^.^.^.^.^.^........
.............................................................................................................................................
.......^...^...^.^.^...^.^.^.....^.^...^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^...^.^...^...^.^.^...^.^.^.^.^.....^...^.^.....^.^.......
.............................................................................................................................................
......^...^.^...^...^...^.^.^...^.^.^.^...^...^.^.^...^.^.....^.^.^...^.....^...^.^...^.......^.^...^.^.....^...^.^.^.^.^.^.^.^.^.^...^......
.............................................................................................................................................
.....^.^.^.^...^.^.....^.^...^.^.......^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^...^...^.^.....
.............................................................................................................................................
....^...^...^.^.^.^...^.^.^...^.^.....^.^.^...^.^.^.^...^.^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.......^.^.^.^.^.....^.^.^.^...^.^.^.^.^...^.^....
.............................................................................................................................................
...^.^...^...^.......^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^...^...^.^...^...^.^.^.^.^.^.^.^.^.....^...^.^...^.^...^.^.^.^...^...
.............................................................................................................................................
..^.^.........^.^.^.^.^.^.^.^.^.^...^.......^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...........^.....^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^..
.............................................................................................................................................
.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.....^.^...^.^.^.^.^.^...^.^...^.^.^.^.^...^...^...^...^.^.^.^.^.^...^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.....^.
.............................................................................................................................................

View File

@@ -0,0 +1,16 @@
.......S.......
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............