You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
828 B
Rust

pub mod a {
static INPUT: &str = include_str!("inputs/day1a.txt");
pub fn go() {
let input = INPUT;
let max = input
.split("\n\n")
.map(|elf_cals_str| {
elf_cals_str
.split('\n')
.filter(|s| !s.is_empty())
.map(|cal_str| cal_str.parse::<u32>().unwrap())
.sum::<u32>()
})
.max()
.unwrap();
println!("{}", max);
}
}
pub mod b {
static INPUT: &str = include_str!("inputs/day1a.txt");
pub fn go() {
let input = INPUT;
let mut cals: Vec<_> = input
.split("\n\n")
.map(|elf_cals_str| {
elf_cals_str
.split('\n')
.filter(|s| !s.is_empty())
.map(|cal_str| cal_str.parse::<u32>().unwrap())
.sum::<u32>()
})
.collect();
cals.sort_by(|a, b| a.cmp(b).reverse());
let total = cals.iter().take(3).sum::<u32>();
println!("{}", total);
}
}