diff --git a/src/day12.rs b/src/day12.rs index fdf8047..9411008 100644 --- a/src/day12.rs +++ b/src/day12.rs @@ -3,7 +3,7 @@ use crate::util::maps::*; const DISCOUNT: bool = true; pub fn day12() { - let mut plots: Map = Map::from_string(&crate::input(12)); + let mut plots: World = World::from_string(&crate::input(12)); let mut regions: Vec = vec![]; for (x, y) in plots.coordinates() { @@ -78,20 +78,20 @@ impl Border { struct Region { pub borders: Vec, - pub tiles: Map, + pub tiles: World, } impl Region { - fn new(x: usize, y: usize, plots: &Map) -> Self { + fn new(x: usize, y: usize, plots: &World) -> Self { let c = plots.get(x, y).unwrap(); - let mut tiles = Map::::from_dimensions(plots.width(), plots.height(), false); + let mut tiles = World::::from_dimensions(plots.width(), plots.height(), false); fn collect_plots( c: char, x: usize, y: usize, - plots: &Map, - tiles: &mut Map, + plots: &World, + tiles: &mut World, ) -> Vec<(usize, usize)> { if plots.get(x, y) != Some(c) || tiles.get(x, y) == Some(true) { return vec![]; diff --git a/src/day15.rs b/src/day15.rs index 5aa1f3b..bd97625 100644 --- a/src/day15.rs +++ b/src/day15.rs @@ -40,11 +40,11 @@ pub fn day15() { } fn move_on_map( - map: &Map, + map: &World, x: usize, y: usize, direction: Direction, -) -> Option> { +) -> Option> { let cascading_move = || { let (nx, ny) = map.travel(x, y, direction)?; let mut downstream = move_on_map(map, nx, ny, direction)?; @@ -82,7 +82,7 @@ fn move_on_map( } } -fn double_wide_map(map: Map) -> Map { +fn double_wide_map(map: World) -> World { let new_map = map .iter_rows() .map(|row| { @@ -100,7 +100,7 @@ fn double_wide_map(map: Map) -> Map { .collect() }) .collect(); - Map::from_2d_vec(new_map) + World::from_2d_vec(new_map) } #[derive(Copy, Clone, Eq, PartialEq, Debug)] @@ -129,7 +129,7 @@ impl Display for Terrain { #[grammar = "grammars/day15.pest"] struct Day15Parser {} -fn parse(input: &str) -> (Map, Vec) { +fn parse(input: &str) -> (World, Vec) { let (map, directions) = Day15Parser::parse(Rule::input, input) .unwrap() .nth(0) @@ -142,7 +142,7 @@ fn parse(input: &str) -> (Map, Vec) { (parse_map(map), parse_directions(directions)) } -fn parse_map(input: Pairs<'_, Rule>) -> Map { +fn parse_map(input: Pairs<'_, Rule>) -> World { let map_vec = input .map(Pair::<'_, Rule>::into_inner) .map(|row| { @@ -156,7 +156,7 @@ fn parse_map(input: Pairs<'_, Rule>) -> Map { .collect() }) .collect(); - Map::from_2d_vec(map_vec) + World::from_2d_vec(map_vec) } fn parse_directions(input: Pairs<'_, Rule>) -> Vec { diff --git a/src/day16.rs b/src/day16.rs index eb41665..87e0d5d 100644 --- a/src/day16.rs +++ b/src/day16.rs @@ -3,8 +3,8 @@ use itertools::Itertools; use std::collections::HashMap; pub fn day16() { - let input: Map = Map::from_string(&crate::input(16)); - let maze: Map = input.map(|&c| c == '.' || c == 'S' || c == 'E'); + let input: World = World::from_string(&crate::input(16)); + let maze: World = input.map(|&c| c == '.' || c == 'S' || c == 'E'); let start: Transform = input .enumerate() @@ -117,11 +117,11 @@ struct Transform<'a> { x: usize, y: usize, direction: Direction, - map: &'a Map, + map: &'a World, } impl<'a> Transform<'a> { - fn new(x: usize, y: usize, direction: Direction, map: &'a Map) -> Self { + fn new(x: usize, y: usize, direction: Direction, map: &'a World) -> Self { Self { x, y, diff --git a/src/util/maps.rs b/src/util/maps.rs index a5af1bf..19ef915 100644 --- a/src/util/maps.rs +++ b/src/util/maps.rs @@ -48,16 +48,16 @@ impl Direction { } #[derive(Clone)] -pub struct Map +pub struct World where T: Copy, { pub map: Vec>, } -impl Map { +impl World { pub fn from_string(string: &str) -> Self { - Map::from_2d_vec( + World::from_2d_vec( string .lines() .filter(|line| !line.is_empty()) @@ -67,7 +67,7 @@ impl Map { } } -impl Map +impl World where T: Copy, { @@ -153,13 +153,13 @@ where self.coordinates().map(|(x, y)| (x, y, &self.map[y][x])) } - pub fn map U>(&self, f: F) -> Map { + pub fn map U>(&self, f: F) -> World { let v = self.map.iter().map(|row| row.iter().map(|e| f(e)).collect()).collect(); - Map::::from_2d_vec(v) + World::::from_2d_vec(v) } } -impl Display for Map +impl Display for World where T: Copy + Display, {