From 5055786d3db80e45a5c3f128f41866ea78865c45 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Thu, 1 Dec 2022 17:43:04 +0300 Subject: 2022, day1: done --- 2022/day1/part2/src/main.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 2022/day1/part2/src/main.rs (limited to '2022/day1/part2/src/main.rs') diff --git a/2022/day1/part2/src/main.rs b/2022/day1/part2/src/main.rs new file mode 100644 index 0000000..2a65d1a --- /dev/null +++ b/2022/day1/part2/src/main.rs @@ -0,0 +1,21 @@ +use itertools::Itertools; + +fn main() { + let input: String = include_str!("../../input").to_string(); + let mut calories: Vec = Vec::new(); + + for (key, group) in &input.lines().group_by(|line| *line != "") { + if key { + calories.push(group.into_iter().map(|i| i.parse::().unwrap()).sum()); + } + } + + println!( + "{}", + calories + .iter() + .sorted_by(|a, b| Ord::cmp(b, a)) + .take(3) + .sum::() + ); +} -- cgit v1.2.3-70-g09d2