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:
16
src/day1.rs
16
src/day1.rs
@@ -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)]
|
||||
|
Reference in New Issue
Block a user