day03 finished
This commit is contained in:
parent
eb1ce68486
commit
d7c85a75f6
8 changed files with 534 additions and 37 deletions
|
|
@ -1,7 +1,6 @@
|
|||
use std::cmp::Ordering;
|
||||
|
||||
use super::template::{DayTrait, ResultType};
|
||||
use anyhow::Result;
|
||||
use thiserror::Error;
|
||||
|
||||
const DAY_NUMBER: usize = 2;
|
||||
|
|
@ -13,11 +12,11 @@ impl DayTrait for Day {
|
|||
DAY_NUMBER
|
||||
}
|
||||
|
||||
fn part1(&self, lines: &str) -> Result<ResultType> {
|
||||
fn part1(&self, lines: &str) -> anyhow::Result<ResultType> {
|
||||
let sum = lines
|
||||
.split("\n")
|
||||
.map(RPS::parse_line)
|
||||
.collect::<Result<Vec<_>>>()?
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
.into_iter()
|
||||
.map(|(first, second)| second.asses_pair(&first))
|
||||
.sum();
|
||||
|
|
@ -25,11 +24,11 @@ impl DayTrait for Day {
|
|||
Ok(ResultType::IntResult(sum))
|
||||
}
|
||||
|
||||
fn part2(&self, lines: &str) -> Result<ResultType> {
|
||||
fn part2(&self, lines: &str) -> anyhow::Result<ResultType> {
|
||||
let sum = lines
|
||||
.split("\n")
|
||||
.map(Strategy::parse_line)
|
||||
.collect::<Result<Vec<_>>>()?
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
.into_iter()
|
||||
.map(|(first, second)| second.fullfill(&first).asses_pair(&first))
|
||||
.sum();
|
||||
|
|
@ -55,7 +54,7 @@ enum RPS {
|
|||
}
|
||||
|
||||
impl RPS {
|
||||
pub fn parse_line(line: &str) -> Result<(Self, Self)> {
|
||||
pub fn parse_line(line: &str) -> Result<(Self, Self), RPSError> {
|
||||
let mut parts = line.split(" ");
|
||||
let (Some(first), Some(second)) = (parts.next(), parts.next()) else {
|
||||
Err(RPSError::IllegalLine(line.to_owned()))?
|
||||
|
|
@ -119,7 +118,7 @@ enum Strategy {
|
|||
}
|
||||
|
||||
impl Strategy {
|
||||
pub fn parse_line(line: &str) -> Result<(RPS, Self)> {
|
||||
pub fn parse_line(line: &str) -> Result<(RPS, Self), RPSError> {
|
||||
let mut parts = line.split(" ");
|
||||
let (Some(first), Some(second)) = (parts.next(), parts.next()) else {
|
||||
Err(RPSError::IllegalLine(line.to_owned()))?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue