feat: day 1
This commit is contained in:
parent
14332c34ef
commit
b60e991f6d
2 changed files with 2279 additions and 0 deletions
2244
inputs/1.txt
Normal file
2244
inputs/1.txt
Normal file
File diff suppressed because it is too large
Load diff
35
src/bin/day_1.rs
Normal file
35
src/bin/day_1.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
use color_eyre::{eyre::eyre, Result};
|
||||||
|
|
||||||
|
fn parse(s: String) -> Result<Vec<(usize, usize)>> {
|
||||||
|
let mut elves = vec![];
|
||||||
|
|
||||||
|
let mut current_elf = 1;
|
||||||
|
let mut current_sum = 0;
|
||||||
|
|
||||||
|
for line in s.lines() {
|
||||||
|
if line.is_empty() {
|
||||||
|
elves.push((current_elf, current_sum));
|
||||||
|
current_elf += 1;
|
||||||
|
current_sum = 0;
|
||||||
|
} else {
|
||||||
|
current_sum += line.parse::<usize>()?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(elves)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let mut input = aoc_2022::load_data(1, parse)?;
|
||||||
|
|
||||||
|
input.sort_by_key(|(_, sum)| *sum);
|
||||||
|
let max = input[input.len() - 1].1;
|
||||||
|
|
||||||
|
println!("The most calories carried by one elf is {max}!");
|
||||||
|
|
||||||
|
let top_three = input[input.len() - 1].1 + input[input.len() - 2].1 + input[input.len() - 3].1;
|
||||||
|
|
||||||
|
println!("The top three elves are carring {top_three} calories!");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in a new issue