|
|
|
@ -6,6 +6,8 @@ use std::io::Lines;
|
|
|
|
|
use clap::Arg; |
|
|
|
|
use clap::Command; |
|
|
|
|
|
|
|
|
|
use itertools::Itertools; |
|
|
|
|
|
|
|
|
|
struct Accumulator<B> { |
|
|
|
|
lines: Lines<B>, |
|
|
|
|
current: u32, |
|
|
|
@ -52,7 +54,12 @@ fn main() {
|
|
|
|
|
let file = File::open(filename).expect("Can't read file"); |
|
|
|
|
let reader = BufReader::new(file); |
|
|
|
|
|
|
|
|
|
let mut calories = reader.lines().elf().collect::<Vec<u32>>(); |
|
|
|
|
calories.sort_by(|a, b| b.cmp(a)); |
|
|
|
|
println!("Sum: {:?}", calories.iter().take(3).sum::<u32>()) |
|
|
|
|
let calories = reader |
|
|
|
|
.lines() |
|
|
|
|
.elf() |
|
|
|
|
.sorted_by(|a, b| b.cmp(a)) |
|
|
|
|
.take(3) |
|
|
|
|
.sum::<u32>(); |
|
|
|
|
|
|
|
|
|
println!("Sum: {:?}", calories) |
|
|
|
|
} |
|
|
|
|