25 lines
670 B
Rust
25 lines
670 B
Rust
fn main() {
|
|
const INPUT: &str = include_str!("../input.txt");
|
|
|
|
let split = INPUT.split("\n");
|
|
let mut calories: Vec<u64> = Vec::new();
|
|
|
|
let mut running_total: u64 = 0;
|
|
for s in split {
|
|
if s == "" {
|
|
calories.push(running_total);
|
|
running_total = 0;
|
|
} else {
|
|
running_total += s.trim().parse::<u64>().expect("Invalid input line: {s}!");
|
|
}
|
|
}
|
|
|
|
let max_calories = calories.iter().max().unwrap();
|
|
|
|
println!("Max calories: {max_calories}");
|
|
|
|
calories.sort_by(|a, b| b.cmp(a));
|
|
let top_three = calories[0] + calories[1] + calories[2];
|
|
println!("Sum of top 3: {top_three}");
|
|
}
|