Follow

Advent of code day 1 in rust 

gitlab.com/MisterBiggs/aoc_202

fn part1(food_input: &str) -> usize {    food_input        .split("\n\n")        .collect::<Vec<&str>>()        .into_iter()        .map(|elf| {            elf.split_whitespace()                .map(|food| food.parse::<usize>().unwrap())                .sum()        })        .collect::<Vec<usize>>()        .into_iter()        .max()        .unwrap()}
fn part2(food_input: &str) -> usize {    let mut elves_calories = food_input        .split("\n\n")        .collect::<Vec<&str>>()        .into_iter()        .map(|elf| {            elf.split_whitespace()                .map(|food| food.parse::<usize>().unwrap())                .sum()        })        .collect::<Vec<usize>>();    elves_calories.sort_by(|l, r| r.cmp(l));    elves_calories[..3].iter().sum::<usize>()}
Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.