summaryrefslogtreecommitdiffstats
path: root/2022/day1/part2/src/main.rs
blob: 2a65d1a8b0a253f3269f07ae403abcd74d9cfcd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use itertools::Itertools;

fn main() {
    let input: String = include_str!("../../input").to_string();
    let mut calories: Vec<usize> = Vec::new();

    for (key, group) in &input.lines().group_by(|line| *line != "") {
        if key {
            calories.push(group.into_iter().map(|i| i.parse::<usize>().unwrap()).sum());
        }
    }

    println!(
        "{}",
        calories
            .iter()
            .sorted_by(|a, b| Ord::cmp(b, a))
            .take(3)
            .sum::<usize>()
    );
}