Part 1
This commit is contained in:
parent
3bd6fc2600
commit
f70f537f36
56
2024/rust/src/day11.rs
Normal file
56
2024/rust/src/day11.rs
Normal file
|
@ -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<usize> = 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue