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