Day 1, Part 1 & 2

This commit is contained in:
Aadi Desai 2023-10-10 12:29:38 +01:00
parent b00b5b231c
commit e2427302fc
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
2 changed files with 2266 additions and 0 deletions

18
src/bin/d1.rs Normal file
View file

@ -0,0 +1,18 @@
const INPUT: &str = include_str!("../input/d1p1.txt");
fn main() -> anyhow::Result<()> {
let mut elves = INPUT
.split("\n\n")
.map(|elf| {
elf.split('\n')
.map(|s| s.parse::<usize>().expect("Failed to parse input"))
.sum::<usize>()
})
.collect::<Vec<_>>();
let max = elves.iter().max();
println!("max: {max:?}");
elves.sort_unstable_by(|l, r| r.cmp(l));
let top3 = elves.iter().take(3).sum::<usize>();
println!("top3: {top3:?}");
anyhow::Ok(())
}

2248
src/input/d1p1.txt Normal file

File diff suppressed because it is too large Load diff