use nalgebra::{DMatrix, Point2, Unit, Vector2}; use nom::{ character::complete::{line_ending, satisfy}, combinator::{map, map_res}, multi::{many1, separated_list1}, IResult, }; use std::fs; fn main() -> Result<(), Box> { let input = fs::read_to_string("inputs/day_17.txt")?; let parsed = HeatlossMap::parser(&input).unwrap().1; dbg!(&parsed.find_shortest_heatloss_path()); Ok(()) } #[derive(Debug)] struct HeatlossMap(DMatrix); #[derive(Debug)] struct Position { pos: Point2, facing: Unit>, duration_with_facing: usize, } impl HeatlossMap { fn parser(input: &str) -> IResult<&str, Self> { map( separated_list1( line_ending, many1(map_res(satisfy(|c| c.is_digit(10)), |d| { d.to_string().parse::() })), ), |digits_vec| { HeatlossMap(DMatrix::from_iterator( digits_vec.len(), digits_vec[0].len(), digits_vec.into_iter().flat_map(|row| row.into_iter()), )) }, )(input) } fn find_shortest_heatloss_path(&self) -> usize { let start = Position { pos: Point2::new(0, 0), facing: Vector2::x_axis(), duration_with_facing: 0, }; dbg!(&start); dbg!(self.0.get((start.pos.x, start.pos.y))); let moved_pos = start.pos + *start.facing; dbg!(&moved_pos); dbg!(self.0.get((moved_pos.x, moved_pos.y))); // start is 0,0 // end is max,max // can't go more than 3 in a straight line // can only turn left or right, not go backwards // todo!() } }