mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 09:23:17 -09:00
28 lines
671 B
Rust
28 lines
671 B
Rust
type Data = Vec<Vec<i32>>;
|
|
|
|
fn parse(input: &str) -> Data {
|
|
input
|
|
.split("\n\n")
|
|
.map(|lines| lines.lines().map(|line| line.parse().unwrap()).collect())
|
|
.collect()
|
|
}
|
|
|
|
fn part_one(data: Data) -> i32 {
|
|
data.iter().map(|cals| cals.iter().sum()).max().unwrap()
|
|
}
|
|
|
|
fn part_two(data: Data) -> i32 {
|
|
let mut cals: std::collections::BinaryHeap<i32> =
|
|
data.iter().map(|cals| cals.iter().sum()).collect();
|
|
cals.pop().unwrap() + cals.pop().unwrap() + cals.pop().unwrap()
|
|
}
|
|
|
|
advent_of_code_macro::generate_tests!(
|
|
day 1,
|
|
parse,
|
|
part_one,
|
|
part_two,
|
|
sample tests [24_000, 45_000],
|
|
star tests [68_923, 200_044]
|
|
);
|