1
0
Fork 0

Solve day 1

This commit is contained in:
Lars Martens 2022-12-01 06:47:17 +01:00
parent fbfffff512
commit 661a1e5878
Signed by: haselkern
GPG key ID: B5CF1F363C179AD4
2 changed files with 2277 additions and 0 deletions

28
src/bin/01.rs Normal file
View file

@ -0,0 +1,28 @@
use aoc2022::*;
const INPUT: &str = include_str!("../../input/01");
fn main() {
let calories = INPUT.lines().map(|l| l.parse::<i64>().ok());
let mut elves = Vec::new();
let mut current = 0;
for c in calories {
match c {
Some(c) => current += c,
None => {
elves.push(current);
current = 0;
}
}
}
// Sort highest number first
elves.sort_by_key(|e| -e);
let max = elves[0];
solved_level_1(max);
let sum: i64 = elves.iter().take(3).sum();
solved_level_2(sum);
}