2022 - Day 1
This commit is contained in:
parent
c889b75029
commit
a6a2385a85
2275
2022/input/1/input
Normal file
2275
2022/input/1/input
Normal file
File diff suppressed because it is too large
Load Diff
16
2022/input/1/test
Normal file
16
2022/input/1/test
Normal 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
41
2022/src/bin/day1.rs
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user