From b23c4ab4c0669ee3af5dd9f2c4e33f51c776fc17 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 6 Dec 2022 22:05:49 +0100 Subject: day 1 more readble --- 2022/day1/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to '2022') diff --git a/2022/day1/src/lib.rs b/2022/day1/src/lib.rs index 26df697..9459264 100644 --- a/2022/day1/src/lib.rs +++ b/2022/day1/src/lib.rs @@ -1,16 +1,16 @@ pub fn get_sums(input: &str) -> Vec { - let groups: Vec<&str> = input.split("\n\n").collect::>(); - let data_groups = groups + let groups: Vec<&str> = input.split("\n\n").collect(); + let data_groups: Vec = groups .into_iter() .map(|x| { let numbers: i32 = x - .split('\n') + .lines() .map(|x| x.parse::().unwrap_or_default()) .sum(); return numbers; }) - .collect::>(); + .collect(); data_groups } @@ -25,9 +25,7 @@ pub fn part2(input: &str) -> i32 { let mut sums = get_sums(input); sums.sort(); - sums.reverse(); - - sums[0] + sums[1] + sums[2] + sums.into_iter().rev().take(3).sum::() } #[cfg(test)] -- cgit v1.2.3-18-g5258