Advent 2025 Day 7 Part 1 & 2
This commit is contained in:
parent
d7b5a2ffaa
commit
96b06c7bee
6 changed files with 250 additions and 2 deletions
142
advent_of_code_2025/src/day7/input.txt
Normal file
142
advent_of_code_2025/src/day7/input.txt
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
......................................................................S......................................................................
|
||||
.............................................................................................................................................
|
||||
......................................................................^......................................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................................^.^.....................................................................
|
||||
.............................................................................................................................................
|
||||
....................................................................^.^.^....................................................................
|
||||
.............................................................................................................................................
|
||||
...................................................................^.....^...................................................................
|
||||
.............................................................................................................................................
|
||||
..................................................................^...^.^.^..................................................................
|
||||
.............................................................................................................................................
|
||||
.................................................................^.^...^.^.^.................................................................
|
||||
.............................................................................................................................................
|
||||
................................................................^...^.^.^.^.^................................................................
|
||||
.............................................................................................................................................
|
||||
...............................................................^.^.^.^.^.^.^.^...............................................................
|
||||
.............................................................................................................................................
|
||||
..............................................................^.^...^.^.^.^...^..............................................................
|
||||
.............................................................................................................................................
|
||||
.............................................................^.^.^.^.^.^.^.^.^.^.............................................................
|
||||
.............................................................................................................................................
|
||||
............................................................^.^.^.............^.^............................................................
|
||||
.............................................................................................................................................
|
||||
...........................................................^.....^.....^.^.^.^.^.^...........................................................
|
||||
.............................................................................................................................................
|
||||
..........................................................^...^.^.^.^.^...^.^.....^..........................................................
|
||||
.............................................................................................................................................
|
||||
.........................................................^.^.^.^.^.....^.^.^.^.^.^.^.........................................................
|
||||
.............................................................................................................................................
|
||||
........................................................^.^...^.....^.^.^.^...^.^.^.^........................................................
|
||||
.............................................................................................................................................
|
||||
.......................................................^.^.^.^.^.^.^.........^.^.^.^.^.......................................................
|
||||
.............................................................................................................................................
|
||||
......................................................^.^.^.......^.^.^.^.^...^.......^......................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................^.^.^.^.^.^.....^...^.^.^.^.^...^.^.....................................................
|
||||
.............................................................................................................................................
|
||||
....................................................^.^.^.....^...^.^...^.....^...^.^.^.^....................................................
|
||||
.............................................................................................................................................
|
||||
...................................................^...^.^.^.....^.^.^.^.^...^.^.......^.^...................................................
|
||||
.............................................................................................................................................
|
||||
..................................................^.^.^.^.^.^.^...^.^.....^.^.......^.^.^.^..................................................
|
||||
.............................................................................................................................................
|
||||
.................................................^.^.^.^.^...^.^.^.^.^.^...^.......^.^.^.^.^.................................................
|
||||
.............................................................................................................................................
|
||||
................................................^.^.......^.^.^.^.......^.^.^.........^...^.^................................................
|
||||
.............................................................................................................................................
|
||||
...............................................^.^.^.^.^.^.....^.^.^.^.^.^.^...^.....^.^.^...^...............................................
|
||||
.............................................................................................................................................
|
||||
..............................................^.........^.^...^.^.^.^.^.^.^.....^.....^.^.^.^.^..............................................
|
||||
.............................................................................................................................................
|
||||
.............................................^.^...^.^.^.^.^.^...^.^.......^.....^.......^.^.^.^.............................................
|
||||
.............................................................................................................................................
|
||||
............................................^...^...^.^.^.^.^.^.....^.^...^.^.^.^.^.^.^.......^.^............................................
|
||||
.............................................................................................................................................
|
||||
...........................................^.^.^.^.^.^.^.^.......^.......^.^.^.......^.....^...^.^...........................................
|
||||
.............................................................................................................................................
|
||||
..........................................^.^.^.....^.....^...^.^.^.^...^.^.^.^...^.^.^.....^...^.^..........................................
|
||||
.............................................................................................................................................
|
||||
.........................................^...^.^.^.^...^.^.^...^.^.^...^.^...^.^...^.^.^.^.^...^...^.........................................
|
||||
.............................................................................................................................................
|
||||
........................................^.^.^.^.^.^.^.......^.^.^.^...^.^...^.^.^.^.^.^.....^.^...^.^........................................
|
||||
.............................................................................................................................................
|
||||
.......................................^.^.^.^.^...^.^...^.^.^.^.....^...^.^.^.....^.^...^.^.^.^.....^.......................................
|
||||
.............................................................................................................................................
|
||||
......................................^...^.^.^.^.^...^.^.^...^...^.^.^.^...^.^...^.^.^.......^...^.^.^......................................
|
||||
.............................................................................................................................................
|
||||
.....................................^.^...^.^.^...^.^.^.^.....^.^.^.^.^.^...^...^.^.^.....^...^.^.^.^.^.....................................
|
||||
.............................................................................................................................................
|
||||
....................................^.^.^...^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^...^.^.^.^.^.^....................................
|
||||
.............................................................................................................................................
|
||||
...................................^.^.....^.^.....^.......^.^.^.....^.......^.^.......^...^.^.^.^.^.^.^.^...................................
|
||||
.............................................................................................................................................
|
||||
..................................^.^...^.^...........^...^.^.^.^...^...^.^...^.^...^.^.^.^.^.^.^.^.^.^...^..................................
|
||||
.............................................................................................................................................
|
||||
.................................^.^.^.^.^...^.^.........^...^.^.........^...^.^.^.^.^.^.^.^.^.^.^.....^.^.^.................................
|
||||
.............................................................................................................................................
|
||||
................................^.^.^.^.^.^.^.^.......^.....^.^.^...^...^...^.^.^...^.^.....^.^.^.......^.^.^................................
|
||||
.............................................................................................................................................
|
||||
...............................^.^.^...^...^.^.....^.^.^.^.^.....^...^.^.^.^.^.^.^.^.^.^...^.^.....^.^.......^...............................
|
||||
.............................................................................................................................................
|
||||
..............................^.^.^.^.^.^...^.^.^.^.^...^.^.^.^.^...........^.^.^.^...^.....^.....^.....^.^...^..............................
|
||||
.............................................................................................................................................
|
||||
.............................^...^.^.^.^.....^.....^...^...............^.....^.^...^...^.^.......^.^.^...^.^...^.............................
|
||||
.............................................................................................................................................
|
||||
............................^.^.^.......^.^.^.^.....^.^.^.^.^.^...^...^.^.........^.^.^.^.^.^.^.^...^.^.^.....^.^............................
|
||||
.............................................................................................................................................
|
||||
...........................^.^.^.....^.^.......^...^.^.....^.^...^.^.^.^...^.^.^.^.^.^.^...^.^.^.^.....^.....^.^.^...........................
|
||||
.............................................................................................................................................
|
||||
..........................^.^...^.^.^.^.....^...^...^.^.^...^.^.^.......^.^...^...^...^.^.^.^.^.^...^...^.^.......^..........................
|
||||
.............................................................................................................................................
|
||||
.........................^.....^.^.^.....^.^.^...^...^.^.....^.^.^...^.^...^.^.^.^.^.^.^...^.^.......^.^.^...^.^...^.........................
|
||||
.............................................................................................................................................
|
||||
........................^.^.....^.......^.^.^.^.^.^.^.......^.^.^.^...^...^.^.^...^...^.^.^.^.^.....^.^.^.^...^...^.^........................
|
||||
.............................................................................................................................................
|
||||
.......................^.^.^.^.^...^...^.^.....^.^.^.^...^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.^...^.^.....^.^.^.^.......................
|
||||
.............................................................................................................................................
|
||||
......................^...^...^...^...^.^.^.^...^.^.^.....^.^.^.^.^.^.^.....^...^.^.^.....^...........^...^...^.^...^.^......................
|
||||
.............................................................................................................................................
|
||||
.....................^.^.^.^.^.^...^.^.^...^.^.^...^.^...^.....^.^.^.^.^.^.^.^.^...^.^.^.....^.^...^.^.^.^...^.^.^.^.^.^.....................
|
||||
.............................................................................................................................................
|
||||
....................^...^.........^.^...^...^...^...^.^...^.^.^...^.^.^...............^...^.....^.......^.........^.^.^.^....................
|
||||
.............................................................................................................................................
|
||||
...................^.^.^.^.^.......^.^.^.^.^.....^.......^.^.^...^...^.^.^...^.^.^.^.^.^.^.^.^.......^.^.^.^.^.^.^.....^.^...................
|
||||
.............................................................................................................................................
|
||||
..................^.........^...^...^...^.^.^.^.^...^.^...^.^.....^.....^.^.^.^.^.....^...^.^.^...^.^...^.^.^.....^.......^..................
|
||||
.............................................................................................................................................
|
||||
.................^.^.^.^.^.^...^.^...^.....^.^...^.^.^.^.^.^.^.^.^...^.^.^.^.....^.^.^.....^...^...^...^...^.^.....^...^...^.................
|
||||
.............................................................................................................................................
|
||||
................^.^.^.^...^.^.^.^.^...^.^.^.^.^.^...^...^...^...^.^.^.^.^.^.^.^.....^.^.^...^...^.^.^.^...^.^.^.^.^.^.^.^.^.^................
|
||||
.............................................................................................................................................
|
||||
...............^...^.^.^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^...^...^.^.^.^...^...^.^.^.^...^...^.....^.^...^.^.^.^.^.....^.^.^...............
|
||||
.............................................................................................................................................
|
||||
..............^...^...^.^.^.^...^.^...^...^.....^...^...^.^...^...^...^.^...^...^.^...^.^...^...^.^.^.....^.^...^.........^...^..............
|
||||
.............................................................................................................................................
|
||||
.............^.^.^...^.....^.^.^.....^.....^.......^...^.^.^...^.^.^.^.^...^...^.^.^.^...^.^...^.^.^...^...^.^.^...^.^.^...^...^.............
|
||||
.............................................................................................................................................
|
||||
............^.......^.^.^.^.^.......^.^.^.^.^.^.^.^.^.^.^.^.....^...^.^.^.^.^.^.^.^.........^...^.^.^.^.^.^.....^.^.^...^.^.^...^............
|
||||
.............................................................................................................................................
|
||||
...........^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.....^.^.^.^...^...^.^.^.....^.^.....^.^.^.^.^...^...^.^...........
|
||||
.............................................................................................................................................
|
||||
..........^.^.^...^.^.^.^.^.^...^.^.^.....^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.....^.^.^...^.^.^.^.^...^.....^.^.......^.^.^.....^...^..........
|
||||
.............................................................................................................................................
|
||||
.........^...^...^.^...^.^.^.^.^.^.^.^.....^.^...^...^...^.^.....^...^.^.^.^...^.^.^.^.^...^.^.^.........^.^.^.^.....^.....^...^...^.........
|
||||
.............................................................................................................................................
|
||||
........^.^...^...^.....^.^.^.^.^...^.^.^.^.....^.^...^.^.^.^.^...^.^...^...^.^.^.......^.......^.^.^.^.^...^.^.^.....^...^.^.....^.^........
|
||||
.............................................................................................................................................
|
||||
.......^.^.^.^.^.^.^.^.^...^.^.^.^.^.....^...^.....^.^.^...^.....^...^.....^.^...^.^.^.^.^.^.^.....^.^.^.^.^.....^.^...^.^.^.^...^.^.^.......
|
||||
.............................................................................................................................................
|
||||
......^.^...^.^.^.^.........^.^.....^.^.^.^...^.^.^.^.^.^...^...^.^.^.^.......^.^.^...^...^.^.^.^...........^.^.^...^.^.^...^.^.^.^.^.^......
|
||||
.............................................................................................................................................
|
||||
.....^.^.^.^.^.^.^.^.^.^.......^.^.^.....^.^.^.^.^...^...^.^...^.^.^.^.^.^.^.^...^.^...^.^.^...^...^.^.^.^.^.....^.^.^.^.^...^.^...^...^.....
|
||||
.............................................................................................................................................
|
||||
....^...^.^.^.^.^.^.^.^...^.^...^...^.^.^.^.....^.^.^.^.....^.^.^.^.^...^.^.^...^.^.^.^.^.^.....^.^.^.^...^...^.^.....^.^.^...^.^.^.^.^.^....
|
||||
.............................................................................................................................................
|
||||
...^.^.^.^.^...^.^.^...^.^.^.^.^...^.^.^...^.^...^.^...^.^.^.^.^.^.^...^...^.^.^.^...^...^.^...^...^.^.^.^.^.^.^.^...^.^.^...^.^...^.^...^...
|
||||
.............................................................................................................................................
|
||||
..^.^.^.^.....^.........^...^.....^...^.....^.^.^.....^...^.^.^.^.^...^.^.^.^.^...^.....^.^...^.^...^.^.^...^.^.^.^.....^.^.^...^.^...^.^.^..
|
||||
.............................................................................................................................................
|
||||
.^.^.^.^.^.....^.^.^.^.^.^.....^...^...^.^.^.^...^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^...^.....^.....^.^.^...^.^.^.^.^...^.^.^.
|
||||
.............................................................................................................................................
|
||||
2
advent_of_code_2025/src/day7/mod.rs
Normal file
2
advent_of_code_2025/src/day7/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod part1;
|
||||
pub mod part2;
|
||||
42
advent_of_code_2025/src/day7/part1.rs
Normal file
42
advent_of_code_2025/src/day7/part1.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
fn print_map(rows: &[Vec<u8>]) {
|
||||
for row in rows {
|
||||
println!("{}", unsafe { str::from_utf8_unchecked(row) });
|
||||
}
|
||||
}
|
||||
|
||||
pub fn solve(input: &str) {
|
||||
let mut rows = input.lines().map(|line| line.as_bytes().to_vec()).collect::<Vec<_>>();
|
||||
let (beam, _) = rows[0].iter().enumerate().find(|(_, ch)| **ch == b'S').unwrap();
|
||||
|
||||
let mut beams = [false].repeat(rows[0].len());
|
||||
let mut new_beams = beams.clone();
|
||||
beams[beam] = true;
|
||||
// print_map(&rows);
|
||||
|
||||
let mut splits = 0;
|
||||
|
||||
for row in rows.iter_mut() {
|
||||
for (idx, active) in beams.iter().enumerate() {
|
||||
if !active {
|
||||
continue;
|
||||
}
|
||||
|
||||
if row[idx] == b'^' {
|
||||
splits += 1;
|
||||
new_beams[idx - 1] = true;
|
||||
new_beams[idx] = false;
|
||||
new_beams[idx + 1] = true;
|
||||
row[idx - 1] = b'|';
|
||||
row[idx + 1] = b'|';
|
||||
} else {
|
||||
row[idx] = b'|';
|
||||
new_beams[idx] = true;
|
||||
}
|
||||
}
|
||||
beams = new_beams.clone();
|
||||
new_beams.fill_with(|| false);
|
||||
}
|
||||
|
||||
// print_map(&rows);
|
||||
println!("splits: {splits}");
|
||||
}
|
||||
46
advent_of_code_2025/src/day7/part2.rs
Normal file
46
advent_of_code_2025/src/day7/part2.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
pub fn solve(input: &str) {
|
||||
let rows = input.lines().map(|line| line.as_bytes()).collect::<Vec<_>>();
|
||||
|
||||
let (beam, _) = rows[0].iter().enumerate().find(|(_, ch)| **ch == b'S').unwrap();
|
||||
|
||||
let mut beams = [false].repeat(rows[0].len());
|
||||
let mut new_beams = beams.clone();
|
||||
beams[beam] = true;
|
||||
|
||||
for row in rows.iter() {
|
||||
for (idx, active) in beams.iter().enumerate() {
|
||||
if !active {
|
||||
continue;
|
||||
}
|
||||
|
||||
if row[idx] == b'^' {
|
||||
new_beams[idx - 1] = true;
|
||||
new_beams[idx + 1] = true;
|
||||
} else {
|
||||
new_beams[idx] = true;
|
||||
}
|
||||
}
|
||||
beams = new_beams.clone();
|
||||
new_beams.fill(false);
|
||||
}
|
||||
|
||||
// now we now where the beams land at the bottom level, so now we need to solve it upwards again.
|
||||
let mut timelines = beams.iter().map(|b| if *b { 1u64 } else { 0u64 }).collect::<Vec<_>>();
|
||||
let mut new_timelines = timelines.clone();
|
||||
new_timelines.fill(0);
|
||||
|
||||
for row in rows.iter().rev() {
|
||||
for (idx, fill) in row.iter().enumerate() {
|
||||
if *fill == b'^' {
|
||||
new_timelines[idx] = timelines[idx - 1] + timelines[idx + 1];
|
||||
} else {
|
||||
new_timelines[idx] = timelines[idx];
|
||||
}
|
||||
}
|
||||
|
||||
timelines = new_timelines.clone();
|
||||
new_timelines.fill(0);
|
||||
}
|
||||
|
||||
println!("possible paths: {}", timelines.iter().max().unwrap());
|
||||
}
|
||||
16
advent_of_code_2025/src/day7/test.txt
Normal file
16
advent_of_code_2025/src/day7/test.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
.......S.......
|
||||
...............
|
||||
.......^.......
|
||||
...............
|
||||
......^.^......
|
||||
...............
|
||||
.....^.^.^.....
|
||||
...............
|
||||
....^.^...^....
|
||||
...............
|
||||
...^.^...^.^...
|
||||
...............
|
||||
..^...^.....^..
|
||||
...............
|
||||
.^.^.^.^.^...^.
|
||||
...............
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use paste::paste;
|
||||
mod utility;
|
||||
|
||||
solve_day!{6}
|
||||
// test_day!{6}
|
||||
solve_day!{7}
|
||||
// test_day!{7}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue