chore: clippies
This commit is contained in:
parent
1dd3ce5862
commit
1cd535c2aa
@ -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<T: BufRead>(input: Lines<T>) -> 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<T: BufRead>(input: Lines<T>) -> 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,
|
||||
|
@ -1,11 +1,11 @@
|
||||
use std::{
|
||||
fmt::{self, Debug, Display, Formatter, Write},
|
||||
io::{BufRead, Cursor, Lines},
|
||||
io::{BufRead, Lines},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Grid<T> {
|
||||
data: Vec<T>,
|
||||
pub data: Vec<T>,
|
||||
width: i64,
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ impl<T: Copy + Eq + PartialEq + Display + Debug> Display for Grid<T> {
|
||||
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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user