aoc2022/src/day01.rs

26 lines
713 B
Rust

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 == &"")
.map(|list| list.iter().map(|el| el.parse().unwrap()).collect())
.collect()
}
#[aoc(day1, part1)]
pub fn solve_part1(input: &[Vec<u64>]) -> u64 {
let mut sums = input.iter().map(|el| el.iter().sum()).collect::<Vec<_>>();
sums.sort();
sums.pop().unwrap()
}
#[aoc(day1, part2)]
pub fn solve_part2(input: &[Vec<u64>]) -> u64 {
let mut sums = input.iter().map(|el| el.iter().sum()).collect::<Vec<_>>();
sums.sort();
sums[sums.len() - 3..sums.len()].iter().sum()
}