day 2 solution, minor refactors.

This commit is contained in:
gabe 2022-12-01 14:18:30 -06:00
parent 50fbfd5438
commit d8c125572f
3 changed files with 8 additions and 7 deletions

View file

@ -2,14 +2,13 @@
pub struct Elf(pub Vec<usize>);
pub fn parse(input: &str) -> Vec<Elf> {
input.trim()
input
.trim()
.split("\n\n")
.map(|group| {
Elf(group
.split('\n')
.map(|line| {
line.parse().unwrap()
})
.map(|line| line.parse().unwrap())
.collect())
})
.collect::<Vec<Elf>>()

View file

@ -1,10 +1,12 @@
use crate::parse;
pub fn part2(input: &[parse::Elf]) -> usize {
input
let mut input = input
.iter()
.map(|elf| elf.0.iter().sum::<usize>())
// not sure what to do next here, how do I get the 3 max values from here?
.collect::<Vec<usize>>();
input.sort_unstable();
input[input.len() - 3..].iter().sum()
}
#[cfg(test)]

View file

@ -1,6 +1,6 @@
mod parse;
mod part1;
mod part2;
mod parse;
fn main() {
let _input = include_str!("./input.txt");