You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
mod elven_calories;
|
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::BufRead;
|
|
|
|
use std::io::BufReader;
|
|
|
|
|
|
|
|
use clap::Arg;
|
|
|
|
use clap::Command;
|
|
|
|
use itertools::Itertools;
|
|
|
|
|
|
|
|
use elven_calories::Elvish;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let matches = Command::new("Day1").arg(Arg::new("filename")).get_matches();
|
|
|
|
let filename = matches
|
|
|
|
.get_one::<String>("filename")
|
|
|
|
.expect("Need a filename");
|
|
|
|
println!("Processing {}...", filename);
|
|
|
|
|
|
|
|
let file = File::open(filename).expect("Can't read file");
|
|
|
|
let reader = BufReader::new(file);
|
|
|
|
|
|
|
|
let calories = reader
|
|
|
|
.lines()
|
|
|
|
.elf()
|
|
|
|
.sorted_by(|a, b| b.cmp(a))
|
|
|
|
.take(3)
|
|
|
|
.sum::<u32>();
|
|
|
|
|
|
|
|
println!("Sum: {:?}", calories)
|
|
|
|
}
|