From 1d58f1e24c2fba85fa95a218043a15457b6fb75f Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Fri, 2 Dec 2022 00:20:08 +0000 Subject: [PATCH] nicer with reverse --- src/day_1.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/day_1.rs b/src/day_1.rs index 8da50e7..2e61ddb 100644 --- a/src/day_1.rs +++ b/src/day_1.rs @@ -24,9 +24,7 @@ pub fn part_2(input: &String) -> u64 { }).collect(); elf_calorie_counts.sort_unstable(); + elf_calorie_counts.reverse(); - let start = elf_calorie_counts.len() - 3; - let top_3 = elf_calorie_counts.drain(start..); - - top_3.sum() + elf_calorie_counts.iter().take(3).sum() }