23 lines
575 B
Rust
23 lines
575 B
Rust
fn elf_calorie_counts(input: &str) -> Vec<u64> {
|
|
input.split("\n\n").map(|elf| {
|
|
elf.split_whitespace().map(|meal| meal.parse().unwrap_or(0)).sum()
|
|
}).collect()
|
|
}
|
|
|
|
pub fn part_1(input: &str) -> u64 {
|
|
let mut elf_calorie_counts= elf_calorie_counts(input);
|
|
|
|
elf_calorie_counts.sort_unstable();
|
|
|
|
elf_calorie_counts.pop().unwrap()
|
|
}
|
|
|
|
pub fn part_2(input: &str) -> u64 {
|
|
let mut elf_calorie_counts= elf_calorie_counts(input);
|
|
|
|
elf_calorie_counts.sort_unstable();
|
|
elf_calorie_counts.reverse();
|
|
|
|
elf_calorie_counts.iter().take(3).sum()
|
|
}
|