day 2 solution, minor refactors.
This commit is contained in:
		
							parent
							
								
									50fbfd5438
								
							
						
					
					
						commit
						d8c125572f
					
				
					 3 changed files with 8 additions and 7 deletions
				
			
		| 
						 | 
					@ -2,14 +2,13 @@
 | 
				
			||||||
pub struct Elf(pub Vec<usize>);
 | 
					pub struct Elf(pub Vec<usize>);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn parse(input: &str) -> Vec<Elf> {
 | 
					pub fn parse(input: &str) -> Vec<Elf> {
 | 
				
			||||||
    input.trim()
 | 
					    input
 | 
				
			||||||
 | 
					        .trim()
 | 
				
			||||||
        .split("\n\n")
 | 
					        .split("\n\n")
 | 
				
			||||||
        .map(|group| {
 | 
					        .map(|group| {
 | 
				
			||||||
            Elf(group
 | 
					            Elf(group
 | 
				
			||||||
                .split('\n')
 | 
					                .split('\n')
 | 
				
			||||||
                .map(|line| {
 | 
					                .map(|line| line.parse().unwrap())
 | 
				
			||||||
                    line.parse().unwrap()
 | 
					 | 
				
			||||||
                })
 | 
					 | 
				
			||||||
                .collect())
 | 
					                .collect())
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        .collect::<Vec<Elf>>()
 | 
					        .collect::<Vec<Elf>>()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,10 +1,12 @@
 | 
				
			||||||
use crate::parse;
 | 
					use crate::parse;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn part2(input: &[parse::Elf]) -> usize {
 | 
					pub fn part2(input: &[parse::Elf]) -> usize {
 | 
				
			||||||
    input
 | 
					    let mut input = input
 | 
				
			||||||
        .iter()
 | 
					        .iter()
 | 
				
			||||||
        .map(|elf| elf.0.iter().sum::<usize>())
 | 
					        .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)]
 | 
					#[cfg(test)]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
 | 
					mod parse;
 | 
				
			||||||
mod part1;
 | 
					mod part1;
 | 
				
			||||||
mod part2;
 | 
					mod part2;
 | 
				
			||||||
mod parse;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn main() {
 | 
					fn main() {
 | 
				
			||||||
    let _input = include_str!("./input.txt");
 | 
					    let _input = include_str!("./input.txt");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue