diff --git a/input/day07 b/input/day07 index e69de29..3a88eb3 100644 --- a/input/day07 +++ b/input/day07 @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^.^.^.................................................................... +............................................................................................................................................. +...................................................................^.^...^................................................................... +............................................................................................................................................. +..................................................................^...^...^.................................................................. +............................................................................................................................................. +.................................................................^...^.^.^.^................................................................. +............................................................................................................................................. +................................................................^.^...^.^.^.^................................................................ +............................................................................................................................................. +...............................................................^.^.^.^.^.^...^............................................................... +............................................................................................................................................. +..............................................................^.^...^.^.^.....^.............................................................. +............................................................................................................................................. +.............................................................^.^.^.....^...^.^.^............................................................. +............................................................................................................................................. +............................................................^.^.^.^...^.^.^.^...^............................................................ +............................................................................................................................................. +...........................................................^.^...^.^.^.^.^.......^........................................................... +............................................................................................................................................. +..........................................................^.^...^.^.^.^.^.^.^.^...^.......................................................... +............................................................................................................................................. +.........................................................^.^...^...^...^...^.....^.^......................................................... +............................................................................................................................................. +........................................................^.^.^.^.^.^.^.^.^...^.^...^.^........................................................ +............................................................................................................................................. +.......................................................^.^.^.^...^.^.^.^.^.^.^.^...^.^....................................................... +............................................................................................................................................. +......................................................^.^.^.^...^.^.....^...^.^.^.^.^.^...................................................... +............................................................................................................................................. +.....................................................^...^.^.^.^.^.^...^.^.^...^.^.^.^.^..................................................... +............................................................................................................................................. +....................................................^.^.^.^.^.^.^...^.^.^...^.^.^.......^.................................................... +............................................................................................................................................. +...................................................^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^.^................................................... +............................................................................................................................................. +..................................................^.^...^.^.^...^.^.....^.^.^...^...^.^.^.^.................................................. +............................................................................................................................................. +.................................................^.^.^.^...^...........^.....^.^...^.^.^.^.^................................................. +............................................................................................................................................. +................................................^.^.^...^.....^.^.^.^.^...^...^.^.^.^.^...^.^................................................ +............................................................................................................................................. +...............................................^...^.^.^.^.........^.^.^.^.^.^.^.^...^.^.^...^............................................... +............................................................................................................................................. +..............................................^.^.^.^...^.....^...^.^.^.^.^.........^.^.^.^.^.^.............................................. +............................................................................................................................................. +.............................................^.^...^.^...^.^.^.^.........^.^.^.^.^.^.^...^.^.^.^............................................. +............................................................................................................................................. +............................................^.^.^.....^...^.......^...^.^.....^.^.^.^...^...^...^............................................ +............................................................................................................................................. +...........................................^...^.^...^.^.^.....^.^...^.......^.^...^.^.^.^.......^........................................... +............................................................................................................................................. +..........................................^.^...^.^...^.^.^.^.^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.......................................... +............................................................................................................................................. +.........................................^.^.^.^.^.^.^.^.^.^...^...^.^...^.....^.....^.^.^.^.^.^.^.^......................................... +............................................................................................................................................. +........................................^.^.^.....^.^.^.^.^...^.....^.^.^.^.^...^.^...^.......^.^...^........................................ +............................................................................................................................................. +.......................................^.^.^.^.^.^.^.^...^.^.^.^.^.^.....^.^.^.^.^.^.^...^.^.^.^.^.^.^....................................... +............................................................................................................................................. +......................................^...^.^.^.^.^.^.^...^.....^.^.^.^.^.^.^.^...^.^.^.....^.^.^.^...^...................................... +............................................................................................................................................. +.....................................^.^.^...^.^.....^...^.^...^.^.^.^...^.^.^...^.^.......^...^...^.^.^..................................... +............................................................................................................................................. +....................................^.^.....^.^.^.^.^.^.....^.....^.....^.^...^.^.......^.....^.^.^.^...^.................................... +............................................................................................................................................. +...................................^.^.^.^.^.^.^...^.^.....^.^.^.^...^...^.^.^.^.^.^...^...^...^...^.^...^................................... +............................................................................................................................................. +..................................^.^.^.^...^.^.^.^.^...^.....^...^.^.^.^.^.^.^.^.^.^.....^.^.^.^...^.^.^.^.................................. +............................................................................................................................................. +.................................^...^...^.^.^.^.^.^.^...^.^...^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^...^...^.^................................. +............................................................................................................................................. +................................^.^.^.^.^.....^.^...^.^.^.^.^.^.^.^...^...^.^.^.^.....^.^...^.^...^.....^.^.^................................ +............................................................................................................................................. +...............................^...^.....^.^.^.^...^.^.^.^.^.^.^.....^.......^...^...^.^.^...^...^.....^.^...^............................... +............................................................................................................................................. +..............................^.^.^.^.^.^.^...^.^.^.^.^...^.^.....^...^.^...^.^.^.^.......^.^.^.^.^.^.^...^...^.............................. +............................................................................................................................................. +.............................^.^...^...^.^...^.^.^...^.^.^.^...^...^.^.......^.^.^...^.^.^.^.^...^.^.^.^.^...^.^............................. +............................................................................................................................................. +............................^.^.^.^.^.^.^.^.^...^...^.^.^.^.......^.^.^.^...^.^.^...^.^...^.^.^.^.^.^...^.^.^.^.^............................ +............................................................................................................................................. +...........................^...^.^.^.^.^.^.^.^.^.^.^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^...^.^.....^...^........................... +............................................................................................................................................. +..........................^.^.^...^...^.^.^.^.^.^.....^.....^.^.^.^.^.....^.^.^.^.......^.^.^.^.^...^.^.^.^.^.....^.......................... +............................................................................................................................................. +.........................^.^.^.^.^.^.^.^...^.^.^.^...^.^.^.^.^.^.....^.^.^...^...^...^.....^.....^.^.^...^.^...^...^......................... +............................................................................................................................................. +........................^.....^...^.^...^.....^.^...^...^...^.....^...^.^...^.^.^.^.^.^.^...^.^.^.^.^...^.^.^.^.^...^........................ +............................................................................................................................................. +.......................^.^.^.^.......^.^.^.^.^.^...^...^...^.^...^.^.^.^.^.^.^.^...^.^.^.....^.^...^.^.^.^.........^.^....................... +............................................................................................................................................. +......................^.........^.^.....^.^...^.^.^.^.^.^.^.^...^.^.^...^...^.^...^.^...^.^.^.^.^.^.^...^.^.^.^...^.^.^...................... +............................................................................................................................................. +.....................^.^...^.^...^...^.^.^.^.^...^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^..................... +............................................................................................................................................. +....................^.^...^.^...^...^.^...^.^...^.^.^...^.^.^.^.......^.^.^.^.....^.^.^...^...^.^.^.^.^.^...^.^.^.^.^.^.^.................... +............................................................................................................................................. +...................^.^.^...^.^.....^...^.....^.^.^.^...^.^...^.....^.^.^.^.^.^.^.....^.^.^.......^.^.^.^.^.^.....^.^.^.^.^................... +............................................................................................................................................. +..................^...^...^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^...^...^...^.................. +............................................................................................................................................. +.................^.^...^.^.^.^...^.^.^.^.^...^.^.^.^.^...^...^.^...^...^.^...^...^.^.....^.^.^.^.^.^.^.^.^.^...^.^...^.^...^................. +............................................................................................................................................. +................^.^.^.^...^.^...^.^.^...^.^.^...^.^.^.^...^.....^.....^.^...^.^.^.^...^.^...^.^.^.....^...^.^.^.^...^...^.^.^................ +............................................................................................................................................. +...............^.^.....^.^.^.......^...^.^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.....^.^.....^.^...^.^.^.^.^.^.^.^...^.^.^.^.^............... +............................................................................................................................................. +..............^.^.^.....^.^...^.....^.^.....^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^...^.^.......^.^.^.^.^.^.^.^.^.....^.^.^.^.............. +............................................................................................................................................. +.............^.^...^.^.^.^.....^...^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.^............. +............................................................................................................................................. +............^.....^.^...^.^.^.^.^.^.^.^...^.^.^.^.....^.^.^.^.^...^.^.^.^...^.^.^...........^...^.^...^.^.^.^.^.^.^...^.^.^.....^............ +............................................................................................................................................. +...........^...^.^...^.^.^.^.^.^.^.^.^.^.^.^.....^.....^.^.^.^.^...^.^...^.^.^...^...^...^.^.^.^.......^.....^.^.^.^...^...^.^.^.^........... +............................................................................................................................................. +..........^.^.^.^.^.......^.^.^.^.^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^...^.^...^.^...^.^.....^.^.^.^...^.^.^.^.^.^.^.^.^.....^...^.......... +............................................................................................................................................. +.........^.^.^.^...^.^.^...^.^.^.^...^.^...........^.^...^.^...^.^.^.....^.^.^.^.^...^.^...^.^.....^...^.^.^.^.^.^.^.^.^.^.^.^...^.^......... +............................................................................................................................................. +........^.^.^...^.^.^.^...^.^.^...^.^.^...^...^.^...^...^...^.^.....^.^.....^.....^...^.^.^.^.^.^.....^.^.^.^.^.^.....^.^.^...^.^.^.^........ +............................................................................................................................................. +.......^.^...^...^...^.^.....^.^.^.^...^.^.^.^.....^...^...^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^...^...^.^.^.^.^.^.^.....^.....^....... +............................................................................................................................................. +......^.^.^.....^.......^.^.^.^...^.^...^.^...^.........^.^.^.^.....^.^.^.....^.^...^...^...^.^...^...^...........^...^.^.....^.^.^...^...... +............................................................................................................................................. +.....^.^.^.^.....^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^...........^.^...^.^...^.^...^...^.^.^...^.^...^.......^...^.^.^.^.^.^...^.^.^...^..... +............................................................................................................................................. +....^.^...^...^.^.^.....^.^.^.^.^.^...^.......^.....^...^.^...^.^...^.....^.^.^.^.^.^.......^.^...^...^.^...^.^.^.^.^.^.^.^...^.^.^.^.^.^.... +............................................................................................................................................. +...^.^...^.^...^.^...^.^.^.^.^.^.........^.^.^...^...^...^.^.^...^.^.^.^.^.....^.^...^.........^...^.^.^...^.^...^.....^.......^.^.....^.^... +............................................................................................................................................. +..^.^.^.^.^...^.^...^.^.^...^.^.^...^...^...^.^.^.^.^.^.^...^.^.^...^...^.^...^.^.^.^...^.......^.^.^.^...^.^.......^.^...^.^...^.^.^.^...^.. +............................................................................................................................................. +.^.^.^.^...^...^...^...^.^.....^...^.^.^...^.^.^.^.^.^...^.^.^.^.........^.^.^.^...^.^...^...^.^.....^...^.^.^.^...^.^...^...^.^.^.^.^...^.^. +............................................................................................................................................. \ No newline at end of file diff --git a/input/day07_test1 b/input/day07_test1 index e69de29..8868910 100644 --- a/input/day07_test1 +++ b/input/day07_test1 @@ -0,0 +1,16 @@ +.......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +............... \ No newline at end of file diff --git a/input/day07_test2 b/input/day07_test2 index e69de29..8868910 100644 --- a/input/day07_test2 +++ b/input/day07_test2 @@ -0,0 +1,16 @@ +.......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +............... \ No newline at end of file diff --git a/src/solutions/day06.rs b/src/solutions/day06.rs index bc515e5..c531065 100644 --- a/src/solutions/day06.rs +++ b/src/solutions/day06.rs @@ -61,7 +61,6 @@ impl Solution for Day06 { _ => unreachable!(), }; - println!("Problem: {:?} {}, Result: {}", numbers, op, result); grand_total += result; } Ok(Box::new(grand_total)) diff --git a/src/solutions/day07.rs b/src/solutions/day07.rs index b73a00d..e9f7871 100644 --- a/src/solutions/day07.rs +++ b/src/solutions/day07.rs @@ -5,16 +5,18 @@ pub struct Day07 {} impl Solution for Day07 { fn part1( &self, - _input: &mut Vec, + input: &mut Vec, ) -> Result, Box> { - Ok(Box::new("Ready")) + let (p1, _p2) = self.solve_paths(input); + Ok(Box::new(p1)) } fn part2( &self, - _input: &mut Vec, + input: &mut Vec, ) -> Result, Box> { - Ok(Box::new("Ready")) + let (_p1, p2) = self.solve_paths(input); + Ok(Box::new(p2)) } fn get_day(&self) -> u8 { @@ -22,7 +24,43 @@ impl Solution for Day07 { } } -impl Day07 {} +impl Day07 { + fn solve_paths(&self, input: &Vec) -> (usize, usize) { + let lines: Vec<_> = input.iter().map(String::as_bytes).collect(); + let width = lines[0].len(); + let start = lines[0].iter().position(|&b| b == b'S').unwrap(); + + let mut splits = 0; + let mut current = vec![0; width]; + let mut next = vec![0; width]; + + current[start] = 1; + + for row in lines { + for (i, &count) in current.iter().enumerate() { + if count > 0 { + if row[i] == b'^' { + splits += 1; + + if i > 0 { + next[i - 1] += count; + } + if i < width - 1 { + next[i + 1] += count; + } + } else { + next[i] += count; + } + } + } + + (current, next) = (next, current); + next.fill(0); + } + + (splits, current.iter().sum()) + } +} /// Test from puzzle input #[cfg(test)] @@ -44,7 +82,7 @@ mod test { .unwrap() .to_string(); - assert_eq!(answer, "Ready"); + assert_eq!(answer, "21"); } #[test] @@ -61,6 +99,6 @@ mod test { .unwrap() .to_string(); - assert_eq!(answer, "Ready"); + assert_eq!(answer, "40"); } }