diff options
Diffstat (limited to '2023/src')
-rw-r--r-- | 2023/src/bin/day_23.rs | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/2023/src/bin/day_23.rs b/2023/src/bin/day_23.rs index b3a610b..3a2bd48 100644 --- a/2023/src/bin/day_23.rs +++ b/2023/src/bin/day_23.rs @@ -1,19 +1,51 @@ -use nom::IResult; +use nom::{ + branch::alt, + character::complete::{char, line_ending}, + combinator::{map, value}, + multi::{many1, separated_list1}, + IResult, +}; use std::fs; fn main() -> Result<(), Box<dyn std::error::Error>> { - let input = fs::read_to_string("inputs/day_2.txt")?; - let parsed = Example::parser(&input).unwrap().1; + let input = fs::read_to_string("inputs/day_23.txt")?; + let parsed = ForestMap::parser(&input).unwrap().1; dbg!(&parsed); Ok(()) } #[derive(Debug)] -struct Example; +struct ForestMap(Vec<Vec<ForestTile>>); -impl Example { - fn parser(_input: &str) -> IResult<&str, Self> { - todo!() +#[derive(Debug, Clone)] +enum ForestTile { + Wall, + Open, + SlopeUp, + SlopeDown, + SlopeLeft, + SlopeRight, +} + +impl ForestMap { + fn parser(input: &str) -> IResult<&str, Self> { + map( + separated_list1(line_ending, many1(ForestTile::parser)), + ForestMap, + )(input) + } +} + +impl ForestTile { + fn parser(input: &str) -> IResult<&str, Self> { + alt(( + value(ForestTile::Wall, char('#')), + value(ForestTile::Open, char('.')), + value(ForestTile::SlopeUp, char('^')), + value(ForestTile::SlopeDown, char('v')), + value(ForestTile::SlopeLeft, char('<')), + value(ForestTile::SlopeRight, char('>')), + ))(input) } } |