1
0
mirror of https://gitlab.com/MisterBiggs/aoc-2023-rust.git synced 2025-07-23 22:51:32 +00:00

cleaned up code

This commit is contained in:
2022-12-01 23:07:00 -07:00
parent a12c497551
commit 6fe29ebc99
3 changed files with 26 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
use itertools::Itertools;
use std::fs;
pub fn run() {
@@ -11,33 +12,30 @@ pub fn run() {
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
food_input
.split("\n\n")
.collect::<Vec<&str>>()
.into_iter()
.map(|elf| {
elf.split_whitespace()
.map(|food| food.parse::<usize>().unwrap())
.sum()
.sum::<usize>()
})
.collect::<Vec<usize>>();
elves_calories.sort_by(|l, r| r.cmp(l));
elves_calories[..3].iter().sum::<usize>()
.sorted()
.rev()
.take(3)
.sum()
}
#[cfg(test)]