Solve day 1
This commit is contained in:
parent
fbfffff512
commit
661a1e5878
2 changed files with 2277 additions and 0 deletions
28
src/bin/01.rs
Normal file
28
src/bin/01.rs
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue