1
0

Added day 1 part 2

This commit is contained in:
Ishan Jain 2022-12-01 10:39:51 +05:30
parent 4d6baa1e1d
commit de2df0f8c5
Signed by: ishan
GPG Key ID: 0506DB2A1CC75C27

View File

@ -1,7 +1,6 @@
#![feature(test)] use std::cmp::Reverse;
extern crate test;
const INPUTS: [&'static str; 2] = [ const INPUTS: [&str; 2] = [
include_str!("../inputs/sample.txt"), include_str!("../inputs/sample.txt"),
include_str!("../inputs/input.txt"), include_str!("../inputs/input.txt"),
]; ];
@ -23,12 +22,13 @@ fn main() {
for input in INPUTS.iter() { for input in INPUTS.iter() {
let output = parse(input); let output = parse(input);
let max = output let mut sets: Vec<i64> = output
.into_iter() .into_iter()
.map(|c| c.into_iter().sum::<i64>()) .map(|c| c.into_iter().sum::<i64>())
.max() .collect();
.unwrap();
println!("{}", max); sets.select_nth_unstable_by_key(2, |c| Reverse(*c));
println!("{}", sets.into_iter().take(3).sum::<i64>());
} }
} }