use nalgebra::Point3; use nom::{ bytes::complete::tag, character::complete::{line_ending, u32}, combinator::map, multi::separated_list1, sequence::{separated_pair, tuple}, IResult, }; use std::fs; fn main() -> Result<(), Box> { let input = fs::read_to_string("inputs/day_22.txt")?; let parsed = BrickPile::parser(&input).unwrap().1; dbg!(&parsed); Ok(()) } #[derive(Debug)] struct BrickPile(Vec); #[derive(Debug)] struct Brick { a: Point3, b: Point3, } impl BrickPile { fn parser(input: &str) -> IResult<&str, Self> { map(separated_list1(line_ending, Brick::parser), BrickPile)(input) } } impl Brick { fn parser(input: &str) -> IResult<&str, Self> { map( separated_pair(point_parser, tag("~"), point_parser), |(a, b)| Brick { a, b }, )(input) } } fn point_parser(input: &str) -> IResult<&str, Point3> { map( tuple((u32, tag(","), u32, tag(","), u32)), |(x, _, y, _, z)| Point3::new(x, y, z), )(input) }