From 2d3443907dcb7abbc7d6a780c3345e2a8849e1a9 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 6 Dec 2024 15:36:07 +0100 Subject: [PATCH] made coordinate public --- src/day06.rs | 9 ++++----- src/utils/grid.rs | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/day06.rs b/src/day06.rs index 5a3190c..a888521 100644 --- a/src/day06.rs +++ b/src/day06.rs @@ -3,7 +3,7 @@ use std::{ fs::read_to_string, }; -use crate::utils::grid::Grid; +use crate::utils::grid::{Coord, Grid}; pub fn day_main() { let input = read_to_string("input/day06.txt").unwrap(); @@ -13,7 +13,6 @@ pub fn day_main() { } type RiddleResult = usize; -type Point = (i64, i64); fn part1(input: &str) -> RiddleResult { let (m, pos) = parse(input); @@ -23,7 +22,7 @@ fn part1(input: &str) -> RiddleResult { visited.len() } -fn get_visited(m: &Grid, mut pos: Point, mut dir: char) -> HashSet { +fn get_visited(m: &Grid, mut pos: Coord, mut dir: char) -> HashSet { let mut visited = HashSet::new(); while m.contains_key(pos) { let (x, y) = pos; @@ -60,7 +59,7 @@ fn part2(input: &str) -> RiddleResult { .count() } -fn parse(input: &str) -> (Grid, Point) { +fn parse(input: &str) -> (Grid, Coord) { let mut m = HashMap::new(); let mut pos = None; input.lines().enumerate().for_each(|(y, line)| { @@ -78,7 +77,7 @@ fn parse(input: &str) -> (Grid, Point) { (Grid::from(m), pos.unwrap()) } -fn is_loop(m: &Grid, block: Point, mut pos: Point, mut dir: char) -> bool { +fn is_loop(m: &Grid, block: Coord, mut pos: Coord, mut dir: char) -> bool { let mut visited = HashSet::new(); loop { let (x, y) = pos; diff --git a/src/utils/grid.rs b/src/utils/grid.rs index 3e00910..26b6560 100644 --- a/src/utils/grid.rs +++ b/src/utils/grid.rs @@ -10,7 +10,7 @@ pub struct Grid { content: Vec, } -type Coord = (i64, i64); +pub type Coord = (i64, i64); impl Grid { pub fn from(mut source: HashMap) -> Grid {