day04 finished

This commit is contained in:
Ruediger Ludwig 2023-01-29 15:12:26 +01:00
parent d7c85a75f6
commit 33eb92e9d1
10 changed files with 1184 additions and 55 deletions

View file

@ -12,10 +12,10 @@ impl DayTrait for Day {
DAY_NUMBER
}
fn part1(&self, lines: &str) -> anyhow::Result<ResultType> {
fn part1(&self, lines: &[String]) -> anyhow::Result<ResultType> {
let sum = lines
.split("\n")
.map(RPS::parse_line)
.iter()
.map(|line| RPS::parse_line(&line))
.collect::<Result<Vec<_>, _>>()?
.into_iter()
.map(|(first, second)| second.asses_pair(&first))
@ -24,10 +24,10 @@ impl DayTrait for Day {
Ok(ResultType::IntResult(sum))
}
fn part2(&self, lines: &str) -> anyhow::Result<ResultType> {
fn part2(&self, lines: &[String]) -> anyhow::Result<ResultType> {
let sum = lines
.split("\n")
.map(Strategy::parse_line)
.iter()
.map(|line| Strategy::parse_line(&line))
.collect::<Result<Vec<_>, _>>()?
.into_iter()
.map(|(first, second)| second.fullfill(&first).asses_pair(&first))
@ -155,7 +155,7 @@ impl TryFrom<&str> for Strategy {
#[cfg(test)]
mod test {
use super::*;
use crate::common::file::read_data;
use crate::common::file::read_lines;
use anyhow::Result;
#[test]
@ -182,7 +182,7 @@ mod test {
#[test]
fn test_part1() -> Result<()> {
let day = Day {};
let lines = read_data(day.get_day_number(), "example01.txt")?;
let lines = read_lines(day.get_day_number(), "example01.txt")?;
let expected = ResultType::IntResult(15);
let result = day.part1(&lines)?;
assert_eq!(result, expected);
@ -214,7 +214,7 @@ mod test {
#[test]
fn test_part2() -> Result<()> {
let day = Day {};
let lines = read_data(day.get_day_number(), "example01.txt")?;
let lines = read_lines(day.get_day_number(), "example01.txt")?;
let expected = ResultType::NoResult;
let result = day.part2(&lines)?;
assert_eq!(result, expected);