AoC2022/d01/src/a2.rs

36 lines
579 B
Rust
Raw Normal View History

2022-12-11 18:06:33 +01:00
pub fn run(inp :Vec<String>) {
let mut curr_max = 0;
let mut elves :Vec<i32> = vec![];
inp.iter().for_each(|elem| {
let number = elem.parse::<i32>();
match number {
Ok(n) => {
curr_max += n;
}
Err(_) => {
elves.push(curr_max);
curr_max = 0;
}
}
});
let mut sum = 0;
for _ in 0..3 {
let e = elves.iter_mut().max().unwrap();
sum += *e;
*e = 0;
}
println!("a2: {}", sum);
}