2022-12-01 11:17:42 -06:00
|
|
|
use aoc_runner_derive::{aoc, aoc_generator};
|
|
|
|
|
|
|
|
#[aoc_generator(day1)]
|
|
|
|
pub fn input_generator(input: &str) -> Vec<Vec<u64>> {
|
|
|
|
input
|
|
|
|
.lines()
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.split(|el| el == &"")
|
2022-12-03 08:16:20 -06:00
|
|
|
.map(|list| list.iter().map(|el| el.parse().unwrap()).collect())
|
|
|
|
.collect()
|
2022-12-01 11:17:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[aoc(day1, part1)]
|
|
|
|
pub fn solve_part1(input: &[Vec<u64>]) -> u64 {
|
2022-12-03 08:16:20 -06:00
|
|
|
let mut sums = input.iter().map(|el| el.iter().sum()).collect::<Vec<_>>();
|
2022-12-01 11:17:42 -06:00
|
|
|
sums.sort();
|
|
|
|
sums.pop().unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[aoc(day1, part2)]
|
|
|
|
pub fn solve_part2(input: &[Vec<u64>]) -> u64 {
|
2022-12-03 08:16:20 -06:00
|
|
|
let mut sums = input.iter().map(|el| el.iter().sum()).collect::<Vec<_>>();
|
2022-12-01 11:17:42 -06:00
|
|
|
sums.sort();
|
2022-12-03 08:16:20 -06:00
|
|
|
sums[sums.len() - 3..sums.len()].iter().sum()
|
2022-12-01 11:17:42 -06:00
|
|
|
}
|