diff --git a/2022/01/rust/main.rs b/2022/01/rust/main.rs index c2750d0..7f2c82b 100644 --- a/2022/01/rust/main.rs +++ b/2022/01/rust/main.rs @@ -29,14 +29,14 @@ fn part_a() { } fn part_b() { - let mut result: Vec = include_str!("../input.txt") + let mut result = include_str!("../input.txt") .trim() .split("\n\n") .map(|x| x.lines().map(|x| x.parse::().unwrap()).sum::()) - .collect(); - result.sort(); - let total = &result.as_slice()[result.len() - 3..result.len()]; - println!("B: {:?}", total.iter().sum::()); + .collect::>(); + result.sort_unstable(); + let total = result.into_iter().rev().take(3).sum::(); + println!("B: {}", total); } fn main() {