day 2 solution, minor refactors.
This commit is contained in:
parent
50fbfd5438
commit
d8c125572f
|
@ -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>>()
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
mod parse;
|
||||
mod part1;
|
||||
mod part2;
|
||||
mod parse;
|
||||
|
||||
fn main() {
|
||||
let _input = include_str!("./input.txt");
|
||||
|
|
Loading…
Reference in a new issue