diff --git a/6/src/main.rs b/6/src/main.rs index 71c46c4..7e543f2 100644 --- a/6/src/main.rs +++ b/6/src/main.rs @@ -1,5 +1,4 @@ use bitflags::bitflags; -use std::collections::{HashMap, HashSet}; use std::fmt; use std::fs::File; use std::io::{BufRead, BufReader, Lines}; @@ -58,10 +57,10 @@ impl FacingDirection { } fn pos_ofs(&self, pos: (i64, i64)) -> (i64, i64) { match self { - FacingDirection::Up => (pos.0 + 0, pos.1 + -1), - FacingDirection::Down => (pos.0 + 0, pos.1 + 1), - FacingDirection::Left => (pos.0 + -1, pos.1 + 0), - FacingDirection::Right => (pos.0 + 1, pos.1 + 0), + FacingDirection::Up => (pos.0, pos.1 + -1), + FacingDirection::Down => (pos.0, pos.1 + 1), + FacingDirection::Left => (pos.0 + -1, pos.1), + FacingDirection::Right => (pos.0 + 1, pos.1), } } } @@ -201,7 +200,7 @@ impl Map { }, } } - return RunOutcome::LeftMap; + RunOutcome::LeftMap } } @@ -209,7 +208,6 @@ impl Map { fn problem1(input: Lines) -> u64 { let mut map = Map::from(input); - eprintln!("problem 1"); map.run_guard(); (map.grid.count(b'X') + map.grid.count(b'-') + map.grid.count(b'|') + map.grid.count(b'^')) as u64 @@ -221,14 +219,12 @@ fn problem2(input: Lines) -> u64 { let mut loop_count = 0u64; for y in 0..input_map.grid.height() { for x in 0..input_map.grid.width() { - eprintln!("Replacing ({}, {}) with obstacle", x, y); match input_map.grid.get(x as i64, y as i64) { Some(b'.') => { let mut test_map = input_map.clone(); test_map.grid.set(x as i64, y as i64, b'#'); - match test_map.run_guard() { - RunOutcome::LoopFound => loop_count += 1, - _ => {} + if let RunOutcome::LoopFound = test_map.run_guard() { + loop_count += 1 } } _ => continue, diff --git a/libs/grid/src/lib.rs b/libs/grid/src/lib.rs index 66880a1..d46a378 100644 --- a/libs/grid/src/lib.rs +++ b/libs/grid/src/lib.rs @@ -1,11 +1,11 @@ use std::{ fmt::{self, Debug, Display, Formatter, Write}, - io::{BufRead, Cursor, Lines}, + io::{BufRead, Lines}, }; #[derive(Clone)] pub struct Grid { - data: Vec, + pub data: Vec, width: i64, } @@ -132,7 +132,7 @@ impl Display for Grid { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { for y in 0..self.height() { for x in 0..self.width() { - self.get(x as i64, y as i64).fmt(f); + self.get(x as i64, y as i64).fmt(f)?; } } f.write_char('\n')