36 lines
579 B
Rust
36 lines
579 B
Rust
|
|
||
|
|
||
|
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);
|
||
|
|
||
|
}
|