From f70f537f36f40a22c510beeda0c7e8ec69c26479 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 11 Dec 2024 10:25:42 -0600 Subject: [PATCH] Part 1 --- 2024/rust/src/day11.rs | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 2024/rust/src/day11.rs diff --git a/2024/rust/src/day11.rs b/2024/rust/src/day11.rs new file mode 100644 index 0000000..cf505da --- /dev/null +++ b/2024/rust/src/day11.rs @@ -0,0 +1,56 @@ +mod prelude; +pub use crate::prelude::*; + +fn main() { + let input = day_input(11); + show_answers(part1(&input), part2(&input)); +} + +fn part1(input: &str) -> usize { + stone_blinks(input, 25) +} + +fn stone_blinks(input: &str, count: usize) -> usize { + let mut stones: Vec = input + .trim() + .split(" ") + .map(|s| s.parse().unwrap()) + .collect(); + let mut next_stones = vec![]; + for blink in 0..count { + println!("{blink} {}", stones.len()); + for (_i, s) in stones.iter().enumerate() { + // next_stones.push(*s) + if *s == 0 { + next_stones.push(1); + continue; + } + let ss = s.to_string(); + if ss.len() % 2 == 0 { + let mid = ss.len() / 2; + let (s1, s2) = (ss[0..mid].parse().unwrap(), ss[mid..].parse().unwrap()); + next_stones.push(s1); + next_stones.push(s2); + continue; + } + next_stones.push(s * 2024) + } + stones = next_stones; + next_stones = vec![]; + } + stones.len() +} + +fn part2(input: &str) -> usize {} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test() { + let input = r#"125 17"#; + assert_eq!(part1(input), 55312); + assert_eq!(part2(input), 0); + } +}