day03 finished

This commit is contained in:
Ruediger Ludwig 2023-01-28 06:00:12 +01:00
parent eb1ce68486
commit d7c85a75f6
8 changed files with 534 additions and 37 deletions

View file

@ -1,7 +1,6 @@
use itertools::Itertools;
use std::num::ParseIntError;
use anyhow::Result;
use thiserror::Error;
use super::template::{DayTrait, ResultType};
@ -14,13 +13,13 @@ impl DayTrait for Day {
DAY_NUMBER
}
fn part1(&self, lines: &str) -> Result<ResultType> {
fn part1(&self, lines: &str) -> anyhow::Result<ResultType> {
let vector = Day::parse(lines)?;
let max = vector.iter().max().ok_or(CalorieError::Empty)?;
Ok(ResultType::IntResult(*max))
}
fn part2(&self, lines: &str) -> Result<ResultType> {
fn part2(&self, lines: &str) -> anyhow::Result<ResultType> {
let vector = Day::parse(lines)?;
let sum = vector.iter().sorted_by(|a, b| Ord::cmp(b, a)).take(3).sum();
Ok(ResultType::IntResult(sum))