2022 - Day 1

This commit is contained in:
Dreaded_X 2022-12-02 06:30:20 +01:00
parent c889b75029
commit a6a2385a85
Signed by: Dreaded_X
GPG Key ID: 76BDEC4E165D8AD9
3 changed files with 2332 additions and 0 deletions

2275
2022/input/1/input Normal file

File diff suppressed because it is too large Load Diff

16
2022/input/1/test Normal file
View File

@ -0,0 +1,16 @@
24000
45000
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000

41
2022/src/bin/day1.rs Normal file
View File

@ -0,0 +1,41 @@
use aoc::Solver;
pub struct Day {}
fn main() {
Day::solve();
}
#[test]
fn part1() {
Day::test(aoc::Part::ONE);
}
#[test]
fn part2() {
Day::test(aoc::Part::TWO);
}
impl aoc::Solver for Day {
fn day() -> u8 {
1
}
fn part1(input: &str) -> u32 {
input.split("\n\n")
.map(|elf| elf.split("\n")
.flat_map(|snack| snack.parse::<u32>())
.sum())
.max()
.unwrap()
}
fn part2(input: &str) -> u32 {
let mut elfs: Vec<u32> = input.split("\n\n")
.map(|elf| elf.split("\n")
.flat_map(|snack| snack.parse::<u32>())
.sum())
.collect();
elfs.sort_by(|a, b| b.cmp(a));
elfs.iter().take(3).sum()
}
}