36 lines
873 B
Rust
36 lines
873 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::<u64>().unwrap())
|
|
.collect::<Vec<_>>()
|
|
})
|
|
.collect::<Vec<_>>()
|
|
}
|
|
|
|
#[aoc(day1, part1)]
|
|
pub fn solve_part1(input: &[Vec<u64>]) -> u64 {
|
|
let mut sums = input
|
|
.iter()
|
|
.map(|el| el.iter().sum::<u64>())
|
|
.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::<u64>())
|
|
.collect::<Vec<_>>();
|
|
sums.sort();
|
|
sums[sums.len() - 3..sums.len()].iter().sum::<u64>()
|
|
}
|