switching 2023 day1 and day2 to this error and error-stack
This commit is contained in:
40
2023/Cargo.lock
generated
40
2023/Cargo.lock
generated
@@ -140,6 +140,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"nom",
|
"nom",
|
||||||
"test-log",
|
"test-log",
|
||||||
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -246,9 +247,12 @@ dependencies = [
|
|||||||
name = "day-2"
|
name = "day-2"
|
||||||
version = "2023.0.0"
|
version = "2023.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"error-stack",
|
||||||
"itertools 0.12.0",
|
"itertools 0.12.0",
|
||||||
"log",
|
"log",
|
||||||
"nom",
|
"nom",
|
||||||
|
"test-log",
|
||||||
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -384,7 +388,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"semver",
|
"semver",
|
||||||
"syn 2.0.39",
|
"syn 2.0.47",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -507,7 +511,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn 2.0.47",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -895,18 +899,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.70"
|
version = "1.0.75"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
|
checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.33"
|
version = "1.0.35"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
@@ -1050,7 +1054,7 @@ dependencies = [
|
|||||||
"regex",
|
"regex",
|
||||||
"relative-path",
|
"relative-path",
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
"syn 2.0.39",
|
"syn 2.0.47",
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1063,7 +1067,7 @@ dependencies = [
|
|||||||
"quote",
|
"quote",
|
||||||
"rand",
|
"rand",
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
"syn 2.0.39",
|
"syn 2.0.47",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1141,7 +1145,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn 2.0.47",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1183,9 +1187,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.39"
|
version = "2.0.47"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
|
checksum = "1726efe18f42ae774cc644f330953a5e7b3c3003d3edcecf18850fe9d4dd9afb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -1220,27 +1224,27 @@ checksum = "7ba277e77219e9eea169e8508942db1bf5d8a41ff2db9b20aab5a5aadc9fa25d"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn 2.0.47",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.51"
|
version = "1.0.56"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7"
|
checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror-impl"
|
name = "thiserror-impl"
|
||||||
version = "1.0.51"
|
version = "1.0.56"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df"
|
checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn 2.0.47",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1341,5 +1345,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn 2.0.47",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ num-traits = "0.2.17"
|
|||||||
rustworkx-core = "0.13.2"
|
rustworkx-core = "0.13.2"
|
||||||
pathfinding = "4.8.0"
|
pathfinding = "4.8.0"
|
||||||
test-log = {version="0.2.14", features=["default", "unstable"]}
|
test-log = {version="0.2.14", features=["default", "unstable"]}
|
||||||
|
thiserror = "1.0.56"
|
||||||
|
|
||||||
|
|
||||||
[profile.dhat]
|
[profile.dhat]
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ error-stack.workspace = true
|
|||||||
itertools.workspace = true
|
itertools.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
nom.workspace = true
|
nom.workspace = true
|
||||||
|
thiserror.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
test-log = {workspace=true}
|
test-log = {workspace=true}
|
||||||
|
|||||||
@@ -3,10 +3,22 @@
|
|||||||
use day_1::part1::part1;
|
use day_1::part1::part1;
|
||||||
use day_1::part2::part2;
|
use day_1::part2::part2;
|
||||||
|
|
||||||
fn main() {
|
use error_stack::{Result, ResultExt};
|
||||||
let input = include_str!("./input.txt");
|
use thiserror::Error;
|
||||||
let part1_result = part1(input).unwrap();
|
|
||||||
println!("part 1: {part1_result}");
|
#[derive(Debug, Error)]
|
||||||
let part2_result = part2(input).unwrap();
|
enum Day1Error {
|
||||||
println!("part 2: {part2_result}");
|
#[error("Part 1 failed")]
|
||||||
|
Part1Error,
|
||||||
|
#[error("Part 2 failed")]
|
||||||
|
Part2Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<(), Day1Error> {
|
||||||
|
let input = include_str!("./input.txt");
|
||||||
|
let part1_result = part1(input).change_context(Day1Error::Part1Error)?;
|
||||||
|
println!("part 1: {part1_result}");
|
||||||
|
let part2_result = part2(input).change_context(Day1Error::Part2Error)?;
|
||||||
|
println!("part 2: {part2_result}");
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic)]
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use nom::{
|
use nom::{
|
||||||
self,
|
self,
|
||||||
@@ -9,17 +7,15 @@ use nom::{
|
|||||||
multi::separated_list1,
|
multi::separated_list1,
|
||||||
};
|
};
|
||||||
|
|
||||||
use error_stack::{Context, Report, Result, ResultExt};
|
use error_stack::{Report, Result, ResultExt};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
pub struct Day1Part1Error;
|
pub enum Day1Part1Error {
|
||||||
|
#[error("Problem parsing Day 1")]
|
||||||
impl Context for Day1Part1Error {}
|
ParseError,
|
||||||
|
#[error("Day 1 Input parsed to Empty")]
|
||||||
impl Display for Day1Part1Error {
|
EmptyInput,
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "day 1 part 1 error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Day-1 part 1 of AC2023
|
/// Day-1 part 1 of AC2023
|
||||||
@@ -32,21 +28,16 @@ impl Display for Day1Part1Error {
|
|||||||
pub fn part1(input: &str) -> Result<String, Day1Part1Error> {
|
pub fn part1(input: &str) -> Result<String, Day1Part1Error> {
|
||||||
let (_input, values) = parse_input(input)
|
let (_input, values) = parse_input(input)
|
||||||
.map_err(|x| Report::from(x.to_owned()))
|
.map_err(|x| Report::from(x.to_owned()))
|
||||||
.change_context(Day1Part1Error)?;
|
.change_context(Day1Part1Error::ParseError)?;
|
||||||
trace!("{values:?}");
|
trace!("{values:?}");
|
||||||
values
|
values
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
v.first()
|
v.first()
|
||||||
.and_then(|first| v.last().map(|last| *first * 10 + *last))
|
.and_then(|first| v.last().map(|last| *first * 10 + *last))
|
||||||
.ok_or(Day1Part1Error)
|
.ok_or(Day1Part1Error::EmptyInput)
|
||||||
})
|
|
||||||
.try_fold(0_u32, |sum, number| {
|
|
||||||
let Ok(number) = number else {
|
|
||||||
return Err(Report::from(Day1Part1Error));
|
|
||||||
};
|
|
||||||
Ok(sum + number)
|
|
||||||
})
|
})
|
||||||
|
.try_fold(0_u32, |sum, number| Ok(sum + number?))
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic)]
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::{fmt::Display, ops::Not};
|
use std::ops::Not;
|
||||||
|
|
||||||
use error_stack::{Context, Report, Result};
|
use error_stack::{report, Result};
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
pub struct Day1Part2Error;
|
pub enum Day1Part2Error {
|
||||||
|
#[error("Problem parsing Day-1 Part2")]
|
||||||
impl Context for Day1Part2Error {}
|
ParseError,
|
||||||
|
#[error("Day 1 Input parsed to Empty")]
|
||||||
impl Display for Day1Part2Error {
|
EmptyInput,
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "day 1 part 2 error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Day 1 Part 2 of AOC2023
|
/// Day 1 Part 2 of AOC2023
|
||||||
@@ -34,14 +32,9 @@ pub fn part2(input: &str) -> Result<String, Day1Part2Error> {
|
|||||||
.map(|v| {
|
.map(|v| {
|
||||||
v.first()
|
v.first()
|
||||||
.and_then(|first| v.last().map(|last| *first * 10 + *last))
|
.and_then(|first| v.last().map(|last| *first * 10 + *last))
|
||||||
.ok_or(Day1Part2Error)
|
.ok_or(report!(Day1Part2Error::EmptyInput))
|
||||||
})
|
|
||||||
.try_fold(0_u32, |sum, number| {
|
|
||||||
let Ok(number) = number else {
|
|
||||||
return Err(Report::from(Day1Part2Error));
|
|
||||||
};
|
|
||||||
Ok(sum + number)
|
|
||||||
})
|
})
|
||||||
|
.try_fold(0_u32, |sum, number| Ok(sum + number?))
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +73,7 @@ fn parse_line(line: &str) -> Result<Vec<u32>, Day1Part2Error> {
|
|||||||
.is_empty()
|
.is_empty()
|
||||||
.not()
|
.not()
|
||||||
.then_some(numbers)
|
.then_some(numbers)
|
||||||
.ok_or(Report::from(Day1Part2Error))
|
.ok_or(report!(Day1Part2Error::ParseError))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -11,3 +11,8 @@ repository.workspace = true
|
|||||||
nom.workspace = true
|
nom.workspace = true
|
||||||
itertools.workspace = true
|
itertools.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
error-stack.workspace = true
|
||||||
|
thiserror.workspace = true
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
test-log.workspace = true
|
||||||
|
|||||||
@@ -3,10 +3,22 @@
|
|||||||
use day_2::part1;
|
use day_2::part1;
|
||||||
use day_2::part2;
|
use day_2::part2;
|
||||||
|
|
||||||
fn main() {
|
use error_stack::{Result, ResultExt};
|
||||||
let input = include_str!("./input.txt");
|
use thiserror::Error;
|
||||||
let part1_result = part1(input);
|
|
||||||
println!("part 1: {part1_result}");
|
#[derive(Debug, Error)]
|
||||||
let part2_result = part2(input);
|
enum Day2Error {
|
||||||
println!("part 2: {part2_result}");
|
#[error("Part 1 failed")]
|
||||||
|
Part1Error,
|
||||||
|
#[error("Part 2 failed")]
|
||||||
|
Part2Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<(), Day2Error> {
|
||||||
|
let input = include_str!("./input.txt");
|
||||||
|
let part1_result = part1(input).change_context(Day2Error::Part1Error)?;
|
||||||
|
println!("part 1: {part1_result}");
|
||||||
|
let part2_result = part2(input).change_context(Day2Error::Part2Error)?;
|
||||||
|
println!("part 2: {part2_result}");
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic)]
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
|
use error_stack::{Report, Result, ResultExt};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use nom::{
|
use nom::{
|
||||||
bytes::complete::tag,
|
bytes::complete::tag,
|
||||||
@@ -7,6 +8,13 @@ use nom::{
|
|||||||
multi::separated_list1,
|
multi::separated_list1,
|
||||||
sequence::{preceded, separated_pair},
|
sequence::{preceded, separated_pair},
|
||||||
};
|
};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum Day2Part1Error {
|
||||||
|
#[error("there was a problem parsing")]
|
||||||
|
ParseError,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Round {
|
struct Round {
|
||||||
@@ -23,8 +31,7 @@ struct Game {
|
|||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
fn to_part1(&self) -> Option<u32> {
|
fn to_part1(&self) -> Option<u32> {
|
||||||
if self
|
self.rounds
|
||||||
.rounds
|
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|r| {
|
.find_map(|r| {
|
||||||
//TODO if inverted use find_map
|
//TODO if inverted use find_map
|
||||||
@@ -34,12 +41,8 @@ impl Game {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.is_some()
|
.is_none()
|
||||||
{
|
.then_some(self.id)
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(self.id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,16 +51,18 @@ impl Game {
|
|||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// - input the puszzle input
|
/// - input the puszzle input
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Errors
|
||||||
/// panics whenever the input isn't parsable
|
/// errors whenever the input isn't parsable
|
||||||
pub fn part1(input: &str) -> String {
|
pub fn part1(input: &'static str) -> Result<String, Day2Part1Error> {
|
||||||
let (_, games) = process_input(input).expect("there should be input");
|
let (_, games) = process_input(input)
|
||||||
|
.map_err(|err| Report::from(err.to_owned()))
|
||||||
|
.change_context(Day2Part1Error::ParseError)?;
|
||||||
debug!("{games:?}");
|
debug!("{games:?}");
|
||||||
games
|
Ok(games
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(Game::to_part1)
|
.filter_map(Game::to_part1)
|
||||||
.sum::<u32>()
|
.sum::<u32>()
|
||||||
.to_string()
|
.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_block(input: &str) -> nom::IResult<&str, (u32, String)> {
|
fn process_block(input: &str) -> nom::IResult<&str, (u32, String)> {
|
||||||
@@ -107,9 +112,10 @@ Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
|||||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
|
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
|
||||||
|
|
||||||
#[test]
|
#[test_log::test]
|
||||||
|
#[test_log(default_log_filter = "trace")]
|
||||||
fn part1_works() {
|
fn part1_works() {
|
||||||
let result = part1(INPUT);
|
let result = part1(INPUT).unwrap();
|
||||||
assert_eq!(result, "8".to_string());
|
assert_eq!(result, "8".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic)]
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
|
use error_stack::{Report, Result, ResultExt};
|
||||||
use nom::{
|
use nom::{
|
||||||
bytes::complete::tag,
|
bytes::complete::tag,
|
||||||
character::complete::{self, newline},
|
character::complete::{self, newline},
|
||||||
multi::separated_list1,
|
multi::separated_list1,
|
||||||
sequence::{preceded, separated_pair},
|
sequence::{preceded, separated_pair},
|
||||||
};
|
};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum Day2Part2Error {
|
||||||
|
#[error("there was a problem parsing")]
|
||||||
|
ParseError,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Round {
|
struct Round {
|
||||||
@@ -44,11 +52,13 @@ impl Game {
|
|||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// - input the puszzle input
|
/// - input the puszzle input
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Errors
|
||||||
/// panics whenever the input isn't parsable
|
/// errors whenever the input isn't parsable
|
||||||
pub fn part2(input: &str) -> String {
|
pub fn part2(input: &str) -> Result<String, Day2Part2Error> {
|
||||||
let (_, games) = process_input(input).expect("there should be input");
|
let (_, games) = process_input(input)
|
||||||
games.iter().map(Game::to_power).sum::<u64>().to_string()
|
.map_err(|err| Report::from(err.to_owned()))
|
||||||
|
.change_context(Day2Part2Error::ParseError)?; //expect("there should be input");
|
||||||
|
Ok(games.iter().map(Game::to_power).sum::<u64>().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_block(input: &str) -> nom::IResult<&str, (u32, String)> {
|
fn process_block(input: &str) -> nom::IResult<&str, (u32, String)> {
|
||||||
@@ -98,9 +108,10 @@ Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
|||||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
|
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
|
||||||
|
|
||||||
#[test]
|
#[test_log::test]
|
||||||
|
#[test_log(default_log_filter = "trace")]
|
||||||
fn part2_works() {
|
fn part2_works() {
|
||||||
let result = part2(INPUT);
|
let result = part2(INPUT).unwrap();
|
||||||
assert_eq!(result, "2286".to_string());
|
assert_eq!(result, "2286".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user