From 81ce406018df339f5e8ea1c87dcfe3a7581059c2 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Wed, 14 Dec 2022 17:06:10 -0800 Subject: [PATCH] Comment out day8 because of build errors --- 2022/aoc2022/src/day8.rs | 90 ++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/2022/aoc2022/src/day8.rs b/2022/aoc2022/src/day8.rs index b7a021a..e68244e 100644 --- a/2022/aoc2022/src/day8.rs +++ b/2022/aoc2022/src/day8.rs @@ -1,38 +1,11 @@ +use crate::grid::{Direction, Point}; use std::collections::HashSet; +/* +type UnsignedPoint = Point; + const INPUT: &'static str = include_str!("../../Data/day8-input.txt"); -#[derive(Clone, Copy, Debug)] -enum Direction { - North, - East, - South, - West, -} - -impl Direction { - fn all() -> &'static [Direction] { - &[ - Direction::North, - Direction::East, - Direction::South, - Direction::West, - ] - } -} - -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -struct Point { - x: usize, - y: usize, -} - -impl std::fmt::Display for Point { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "({}, {})", self.x, self.y) - } -} - #[derive(Debug)] struct Grid { grid: Vec>, @@ -51,11 +24,11 @@ impl Grid { self.grid[0].len() } - fn tree_height_at(&self, at: Point) -> Option { - Some(self.grid[at.y][at.x].clone()) + fn tree_height_at(&self, at: UnsignedPoint) -> Option { + Some(self.grid[at.y as usize][at.x as usize].clone()) } - fn scenic_score_at(&self, at: Point) -> i32 { + fn scenic_score_at(&self, at: UnsignedPoint) -> i32 { let height = self.tree_height_at(at); let mut scores = [0, 0, 0, 0]; @@ -77,26 +50,30 @@ impl Grid { total_score } - fn iter_points(&self) -> Box> { - let width = self.width(); + fn iter_points(&self) -> Box> { + let width = self.width() as i32; Box::new( (0..self.height()) - .map(move |y| (0..width).map(move |x| Point { x, y })) + .map(move |y| (0..width).map(move |x| UnsignedPoint::new(x as i32, y as i32))) .flatten(), ) } fn iter_points_from_edge_to_point_in_direction( &self, - point: Point, + point: UnsignedPoint, direction: Direction, - ) -> Box> { - let width = self.width(); - let height = self.height(); + ) -> Box> { + let width = self.width() as i32; + let height = self.height() as i32; - let closure: Box Point> = match direction { - Direction::North | Direction::South => Box::new(move |y| Point { x: point.x, y }), - Direction::East | Direction::West => Box::new(move |x| Point { x, y: point.y }), + let closure: Box UnsignedPoint> = match direction { + Direction::North | Direction::South => { + Box::new(move |y| UnsignedPoint::new(point.x, y as i32)) + } + Direction::East | Direction::West => { + Box::new(move |x| UnsignedPoint::new(x as i32, point.y)) + } }; match direction { @@ -109,15 +86,17 @@ impl Grid { fn iter_points_from_point_to_edge_in_direction( &self, - point: Point, + point: UnsignedPoint, direction: Direction, - ) -> Box> { - let width = self.width(); - let height = self.height(); + ) -> Box> { + let width = self.width() as i32; + let height = self.height() as i32; - let closure: Box Point> = match direction { - Direction::North | Direction::South => Box::new(move |y| Point { x: point.x, y }), - Direction::East | Direction::West => Box::new(move |x| Point { x, y: point.y }), + let closure: Box UnsignedPoint> = match direction { + Direction::North | Direction::South => { + Box::new(move |y| UnsignedPoint::new(point.x, y as i32)) + } + Direction::East | Direction::West => Box::new(move |x| UnsignedPoint::new(x, point.y)), }; match direction { @@ -128,10 +107,10 @@ impl Grid { } } - fn print_with_visible_set(&self, visible_trees: &HashSet) { + fn print_with_visible_set(&self, visible_trees: &HashSet) { for y in 0..self.height() { for x in 0..self.width() { - let pt = Point { x, y }; + let pt = UnsignedPoint::new(x as i32, y as i32); let height = self.tree_height_at(pt).unwrap(); if visible_trees.contains(&pt) { print!("\x1B[32m{}\x1B[0m", height); @@ -143,8 +122,10 @@ impl Grid { } } } +*/ pub fn main(_filename: &str) -> std::io::Result<()> { + /* let grid = Grid::new( INPUT .lines() @@ -156,7 +137,7 @@ pub fn main(_filename: &str) -> std::io::Result<()> { .collect(), ); - let mut visible_trees: HashSet = HashSet::new(); + let mut visible_trees: HashSet = HashSet::new(); let mut highest_scenic_score: i32 = -1; for grid_pt in grid.iter_points() { @@ -205,6 +186,7 @@ pub fn main(_filename: &str) -> std::io::Result<()> { println!("Part 1: Number of visible trees: {}", &visible_trees.len()); println!("Part 2: Highest scenic score: {}", highest_scenic_score); + */ Ok(()) }