mirror of
https://github.com/supleed2/advent-of-code-2022.git
synced 2024-12-22 13:45:52 +00:00
Day 1, Part 1 & 2
This commit is contained in:
parent
b00b5b231c
commit
e2427302fc
18
src/bin/d1.rs
Normal file
18
src/bin/d1.rs
Normal 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
2248
src/input/d1p1.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue