summaryrefslogtreecommitdiffstats
path: root/2022/day1/part2/src/main.rs
blob: 62175ab94c0a8caabab1bbbb398c70077e52bb80 (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.is_empty()) {
        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>()
    );
}