diff --git a/advent_of_code_2025/src/day7/input.txt b/advent_of_code_2025/src/day7/input.txt new file mode 100644 index 0000000..cc6fac6 --- /dev/null +++ b/advent_of_code_2025/src/day7/input.txt @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^.^.^.................................................................... +............................................................................................................................................. +...................................................................^.....^................................................................... +............................................................................................................................................. +..................................................................^...^.^.^.................................................................. +............................................................................................................................................. +.................................................................^.^...^.^.^................................................................. +............................................................................................................................................. +................................................................^...^.^.^.^.^................................................................ +............................................................................................................................................. +...............................................................^.^.^.^.^.^.^.^............................................................... +............................................................................................................................................. +..............................................................^.^...^.^.^.^...^.............................................................. +............................................................................................................................................. +.............................................................^.^.^.^.^.^.^.^.^.^............................................................. +............................................................................................................................................. +............................................................^.^.^.............^.^............................................................ +............................................................................................................................................. +...........................................................^.....^.....^.^.^.^.^.^........................................................... +............................................................................................................................................. +..........................................................^...^.^.^.^.^...^.^.....^.......................................................... +............................................................................................................................................. +.........................................................^.^.^.^.^.....^.^.^.^.^.^.^......................................................... +............................................................................................................................................. +........................................................^.^...^.....^.^.^.^...^.^.^.^........................................................ +............................................................................................................................................. +.......................................................^.^.^.^.^.^.^.........^.^.^.^.^....................................................... +............................................................................................................................................. +......................................................^.^.^.......^.^.^.^.^...^.......^...................................................... +............................................................................................................................................. +.....................................................^.^.^.^.^.^.....^...^.^.^.^.^...^.^..................................................... +............................................................................................................................................. +....................................................^.^.^.....^...^.^...^.....^...^.^.^.^.................................................... +............................................................................................................................................. +...................................................^...^.^.^.....^.^.^.^.^...^.^.......^.^................................................... +............................................................................................................................................. +..................................................^.^.^.^.^.^.^...^.^.....^.^.......^.^.^.^.................................................. +............................................................................................................................................. +.................................................^.^.^.^.^...^.^.^.^.^.^...^.......^.^.^.^.^................................................. +............................................................................................................................................. +................................................^.^.......^.^.^.^.......^.^.^.........^...^.^................................................ +............................................................................................................................................. +...............................................^.^.^.^.^.^.....^.^.^.^.^.^.^...^.....^.^.^...^............................................... +............................................................................................................................................. +..............................................^.........^.^...^.^.^.^.^.^.^.....^.....^.^.^.^.^.............................................. +............................................................................................................................................. +.............................................^.^...^.^.^.^.^.^...^.^.......^.....^.......^.^.^.^............................................. +............................................................................................................................................. +............................................^...^...^.^.^.^.^.^.....^.^...^.^.^.^.^.^.^.......^.^............................................ +............................................................................................................................................. +...........................................^.^.^.^.^.^.^.^.......^.......^.^.^.......^.....^...^.^........................................... +............................................................................................................................................. +..........................................^.^.^.....^.....^...^.^.^.^...^.^.^.^...^.^.^.....^...^.^.......................................... +............................................................................................................................................. +.........................................^...^.^.^.^...^.^.^...^.^.^...^.^...^.^...^.^.^.^.^...^...^......................................... +............................................................................................................................................. +........................................^.^.^.^.^.^.^.......^.^.^.^...^.^...^.^.^.^.^.^.....^.^...^.^........................................ +............................................................................................................................................. +.......................................^.^.^.^.^...^.^...^.^.^.^.....^...^.^.^.....^.^...^.^.^.^.....^....................................... +............................................................................................................................................. +......................................^...^.^.^.^.^...^.^.^...^...^.^.^.^...^.^...^.^.^.......^...^.^.^...................................... +............................................................................................................................................. +.....................................^.^...^.^.^...^.^.^.^.....^.^.^.^.^.^...^...^.^.^.....^...^.^.^.^.^..................................... +............................................................................................................................................. +....................................^.^.^...^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^...^.^.^.^.^.^.................................... +............................................................................................................................................. +...................................^.^.....^.^.....^.......^.^.^.....^.......^.^.......^...^.^.^.^.^.^.^.^................................... +............................................................................................................................................. +..................................^.^...^.^...........^...^.^.^.^...^...^.^...^.^...^.^.^.^.^.^.^.^.^.^...^.................................. +............................................................................................................................................. +.................................^.^.^.^.^...^.^.........^...^.^.........^...^.^.^.^.^.^.^.^.^.^.^.....^.^.^................................. +............................................................................................................................................. +................................^.^.^.^.^.^.^.^.......^.....^.^.^...^...^...^.^.^...^.^.....^.^.^.......^.^.^................................ +............................................................................................................................................. +...............................^.^.^...^...^.^.....^.^.^.^.^.....^...^.^.^.^.^.^.^.^.^.^...^.^.....^.^.......^............................... +............................................................................................................................................. +..............................^.^.^.^.^.^...^.^.^.^.^...^.^.^.^.^...........^.^.^.^...^.....^.....^.....^.^...^.............................. +............................................................................................................................................. +.............................^...^.^.^.^.....^.....^...^...............^.....^.^...^...^.^.......^.^.^...^.^...^............................. +............................................................................................................................................. +............................^.^.^.......^.^.^.^.....^.^.^.^.^.^...^...^.^.........^.^.^.^.^.^.^.^...^.^.^.....^.^............................ +............................................................................................................................................. +...........................^.^.^.....^.^.......^...^.^.....^.^...^.^.^.^...^.^.^.^.^.^.^...^.^.^.^.....^.....^.^.^........................... +............................................................................................................................................. +..........................^.^...^.^.^.^.....^...^...^.^.^...^.^.^.......^.^...^...^...^.^.^.^.^.^...^...^.^.......^.......................... +............................................................................................................................................. +.........................^.....^.^.^.....^.^.^...^...^.^.....^.^.^...^.^...^.^.^.^.^.^.^...^.^.......^.^.^...^.^...^......................... +............................................................................................................................................. +........................^.^.....^.......^.^.^.^.^.^.^.......^.^.^.^...^...^.^.^...^...^.^.^.^.^.....^.^.^.^...^...^.^........................ +............................................................................................................................................. +.......................^.^.^.^.^...^...^.^.....^.^.^.^...^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.^...^.^.....^.^.^.^....................... +............................................................................................................................................. +......................^...^...^...^...^.^.^.^...^.^.^.....^.^.^.^.^.^.^.....^...^.^.^.....^...........^...^...^.^...^.^...................... +............................................................................................................................................. +.....................^.^.^.^.^.^...^.^.^...^.^.^...^.^...^.....^.^.^.^.^.^.^.^.^...^.^.^.....^.^...^.^.^.^...^.^.^.^.^.^..................... +............................................................................................................................................. +....................^...^.........^.^...^...^...^...^.^...^.^.^...^.^.^...............^...^.....^.......^.........^.^.^.^.................... +............................................................................................................................................. +...................^.^.^.^.^.......^.^.^.^.^.....^.......^.^.^...^...^.^.^...^.^.^.^.^.^.^.^.^.......^.^.^.^.^.^.^.....^.^................... +............................................................................................................................................. +..................^.........^...^...^...^.^.^.^.^...^.^...^.^.....^.....^.^.^.^.^.....^...^.^.^...^.^...^.^.^.....^.......^.................. +............................................................................................................................................. +.................^.^.^.^.^.^...^.^...^.....^.^...^.^.^.^.^.^.^.^.^...^.^.^.^.....^.^.^.....^...^...^...^...^.^.....^...^...^................. +............................................................................................................................................. +................^.^.^.^...^.^.^.^.^...^.^.^.^.^.^...^...^...^...^.^.^.^.^.^.^.^.....^.^.^...^...^.^.^.^...^.^.^.^.^.^.^.^.^.^................ +............................................................................................................................................. +...............^...^.^.^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^...^...^.^.^.^...^...^.^.^.^...^...^.....^.^...^.^.^.^.^.....^.^.^............... +............................................................................................................................................. +..............^...^...^.^.^.^...^.^...^...^.....^...^...^.^...^...^...^.^...^...^.^...^.^...^...^.^.^.....^.^...^.........^...^.............. +............................................................................................................................................. +.............^.^.^...^.....^.^.^.....^.....^.......^...^.^.^...^.^.^.^.^...^...^.^.^.^...^.^...^.^.^...^...^.^.^...^.^.^...^...^............. +............................................................................................................................................. +............^.......^.^.^.^.^.......^.^.^.^.^.^.^.^.^.^.^.^.....^...^.^.^.^.^.^.^.^.........^...^.^.^.^.^.^.....^.^.^...^.^.^...^............ +............................................................................................................................................. +...........^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.....^.^.^.^...^...^.^.^.....^.^.....^.^.^.^.^...^...^.^........... +............................................................................................................................................. +..........^.^.^...^.^.^.^.^.^...^.^.^.....^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.....^.^.^...^.^.^.^.^...^.....^.^.......^.^.^.....^...^.......... +............................................................................................................................................. +.........^...^...^.^...^.^.^.^.^.^.^.^.....^.^...^...^...^.^.....^...^.^.^.^...^.^.^.^.^...^.^.^.........^.^.^.^.....^.....^...^...^......... +............................................................................................................................................. +........^.^...^...^.....^.^.^.^.^...^.^.^.^.....^.^...^.^.^.^.^...^.^...^...^.^.^.......^.......^.^.^.^.^...^.^.^.....^...^.^.....^.^........ +............................................................................................................................................. +.......^.^.^.^.^.^.^.^.^...^.^.^.^.^.....^...^.....^.^.^...^.....^...^.....^.^...^.^.^.^.^.^.^.....^.^.^.^.^.....^.^...^.^.^.^...^.^.^....... +............................................................................................................................................. +......^.^...^.^.^.^.........^.^.....^.^.^.^...^.^.^.^.^.^...^...^.^.^.^.......^.^.^...^...^.^.^.^...........^.^.^...^.^.^...^.^.^.^.^.^...... +............................................................................................................................................. +.....^.^.^.^.^.^.^.^.^.^.......^.^.^.....^.^.^.^.^...^...^.^...^.^.^.^.^.^.^.^...^.^...^.^.^...^...^.^.^.^.^.....^.^.^.^.^...^.^...^...^..... +............................................................................................................................................. +....^...^.^.^.^.^.^.^.^...^.^...^...^.^.^.^.....^.^.^.^.....^.^.^.^.^...^.^.^...^.^.^.^.^.^.....^.^.^.^...^...^.^.....^.^.^...^.^.^.^.^.^.... +............................................................................................................................................. +...^.^.^.^.^...^.^.^...^.^.^.^.^...^.^.^...^.^...^.^...^.^.^.^.^.^.^...^...^.^.^.^...^...^.^...^...^.^.^.^.^.^.^.^...^.^.^...^.^...^.^...^... +............................................................................................................................................. +..^.^.^.^.....^.........^...^.....^...^.....^.^.^.....^...^.^.^.^.^...^.^.^.^.^...^.....^.^...^.^...^.^.^...^.^.^.^.....^.^.^...^.^...^.^.^.. +............................................................................................................................................. +.^.^.^.^.^.....^.^.^.^.^.^.....^...^...^.^.^.^...^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^...^.....^.....^.^.^...^.^.^.^.^...^.^.^. +............................................................................................................................................. \ No newline at end of file diff --git a/advent_of_code_2025/src/day7/mod.rs b/advent_of_code_2025/src/day7/mod.rs new file mode 100644 index 0000000..8e2a92e --- /dev/null +++ b/advent_of_code_2025/src/day7/mod.rs @@ -0,0 +1,2 @@ +pub mod part1; +pub mod part2; \ No newline at end of file diff --git a/advent_of_code_2025/src/day7/part1.rs b/advent_of_code_2025/src/day7/part1.rs new file mode 100644 index 0000000..8f2bb14 --- /dev/null +++ b/advent_of_code_2025/src/day7/part1.rs @@ -0,0 +1,42 @@ +fn print_map(rows: &[Vec]) { + 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::>(); + 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}"); +} diff --git a/advent_of_code_2025/src/day7/part2.rs b/advent_of_code_2025/src/day7/part2.rs new file mode 100644 index 0000000..02a7268 --- /dev/null +++ b/advent_of_code_2025/src/day7/part2.rs @@ -0,0 +1,46 @@ +pub fn solve(input: &str) { + let rows = input.lines().map(|line| line.as_bytes()).collect::>(); + + 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::>(); + 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()); +} diff --git a/advent_of_code_2025/src/day7/test.txt b/advent_of_code_2025/src/day7/test.txt new file mode 100644 index 0000000..8868910 --- /dev/null +++ b/advent_of_code_2025/src/day7/test.txt @@ -0,0 +1,16 @@ +.......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +............... \ No newline at end of file diff --git a/advent_of_code_2025/src/main.rs b/advent_of_code_2025/src/main.rs index 6908767..c13cc29 100644 --- a/advent_of_code_2025/src/main.rs +++ b/advent_of_code_2025/src/main.rs @@ -1,5 +1,5 @@ use paste::paste; mod utility; -solve_day!{6} -// test_day!{6} +solve_day!{7} +// test_day!{7}