diff options
Diffstat (limited to '2022/day1/part2/src')
-rw-r--r-- | 2022/day1/part2/src/main.rs | 21 |
1 files changed, 21 insertions, 0 deletions
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 @@ | |||
1 | use itertools::Itertools; | ||
2 | |||
3 | fn main() { | ||
4 | let input: String = include_str!("../../input").to_string(); | ||
5 | let mut calories: Vec<usize> = Vec::new(); | ||
6 | |||
7 | for (key, group) in &input.lines().group_by(|line| *line != "") { | ||
8 | if key { | ||
9 | calories.push(group.into_iter().map(|i| i.parse::<usize>().unwrap()).sum()); | ||
10 | } | ||
11 | } | ||
12 | |||
13 | println!( | ||
14 | "{}", | ||
15 | calories | ||
16 | .iter() | ||
17 | .sorted_by(|a, b| Ord::cmp(b, a)) | ||
18 | .take(3) | ||
19 | .sum::<usize>() | ||
20 | ); | ||
21 | } | ||