1
0

extended the grid with parsing from string and added position iterator

This commit is contained in:
2024-12-06 16:09:20 +01:00
parent 2d3443907d
commit 345b29278f
3 changed files with 59 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
use std::{
collections::{HashMap, HashSet},
collections::HashSet,
fs::read_to_string,
};
@@ -60,21 +60,10 @@ fn part2(input: &str) -> RiddleResult {
}
fn parse(input: &str) -> (Grid<char>, Coord) {
let mut m = HashMap::new();
let mut pos = None;
input.lines().enumerate().for_each(|(y, line)| {
line.char_indices().for_each(|(x, c)| {
let x = x as i64;
let y = y as i64;
if c == '^' {
pos = Some((x, y));
m.insert((x, y), '.');
} else {
m.insert((x, y), c);
}
});
});
(Grid::from(m), pos.unwrap())
let mut m = Grid::parse(input);
let start = m.entries().find(|(_, c)| **c == '^').unwrap().0;
m[start] = '.';
(m, start)
}
fn is_loop(m: &Grid<char>, block: Coord, mut pos: Coord, mut dir: char) -> bool {