chore: clippies
This commit is contained in:
		@@ -1,5 +1,4 @@
 | 
				
			|||||||
use bitflags::bitflags;
 | 
					use bitflags::bitflags;
 | 
				
			||||||
use std::collections::{HashMap, HashSet};
 | 
					 | 
				
			||||||
use std::fmt;
 | 
					use std::fmt;
 | 
				
			||||||
use std::fs::File;
 | 
					use std::fs::File;
 | 
				
			||||||
use std::io::{BufRead, BufReader, Lines};
 | 
					use std::io::{BufRead, BufReader, Lines};
 | 
				
			||||||
@@ -58,10 +57,10 @@ impl FacingDirection {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    fn pos_ofs(&self, pos: (i64, i64)) -> (i64, i64) {
 | 
					    fn pos_ofs(&self, pos: (i64, i64)) -> (i64, i64) {
 | 
				
			||||||
        match self {
 | 
					        match self {
 | 
				
			||||||
            FacingDirection::Up => (pos.0 + 0, pos.1 + -1),
 | 
					            FacingDirection::Up => (pos.0, pos.1 + -1),
 | 
				
			||||||
            FacingDirection::Down => (pos.0 + 0, pos.1 + 1),
 | 
					            FacingDirection::Down => (pos.0, pos.1 + 1),
 | 
				
			||||||
            FacingDirection::Left => (pos.0 + -1, pos.1 + 0),
 | 
					            FacingDirection::Left => (pos.0 + -1, pos.1),
 | 
				
			||||||
            FacingDirection::Right => (pos.0 + 1, pos.1 + 0),
 | 
					            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 {
 | 
					fn problem1<T: BufRead>(input: Lines<T>) -> u64 {
 | 
				
			||||||
    let mut map = Map::from(input);
 | 
					    let mut map = Map::from(input);
 | 
				
			||||||
    eprintln!("problem 1");
 | 
					 | 
				
			||||||
    map.run_guard();
 | 
					    map.run_guard();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (map.grid.count(b'X') + map.grid.count(b'-') + map.grid.count(b'|') + map.grid.count(b'^')) as u64
 | 
					    (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;
 | 
					    let mut loop_count = 0u64;
 | 
				
			||||||
    for y in 0..input_map.grid.height() {
 | 
					    for y in 0..input_map.grid.height() {
 | 
				
			||||||
        for x in 0..input_map.grid.width() {
 | 
					        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) {
 | 
					            match input_map.grid.get(x as i64, y as i64) {
 | 
				
			||||||
                Some(b'.') => {
 | 
					                Some(b'.') => {
 | 
				
			||||||
                    let mut test_map = input_map.clone();
 | 
					                    let mut test_map = input_map.clone();
 | 
				
			||||||
                    test_map.grid.set(x as i64, y as i64, b'#');
 | 
					                    test_map.grid.set(x as i64, y as i64, b'#');
 | 
				
			||||||
                    match test_map.run_guard() {
 | 
					                    if let RunOutcome::LoopFound = test_map.run_guard() {
 | 
				
			||||||
                        RunOutcome::LoopFound => loop_count += 1,
 | 
					                        loop_count += 1
 | 
				
			||||||
                        _ => {}
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                _ => continue,
 | 
					                _ => continue,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,11 +1,11 @@
 | 
				
			|||||||
use std::{
 | 
					use std::{
 | 
				
			||||||
    fmt::{self, Debug, Display, Formatter, Write},
 | 
					    fmt::{self, Debug, Display, Formatter, Write},
 | 
				
			||||||
    io::{BufRead, Cursor, Lines},
 | 
					    io::{BufRead, Lines},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone)]
 | 
					#[derive(Clone)]
 | 
				
			||||||
pub struct Grid<T> {
 | 
					pub struct Grid<T> {
 | 
				
			||||||
    data: Vec<T>,
 | 
					    pub data: Vec<T>,
 | 
				
			||||||
    width: i64,
 | 
					    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 {
 | 
					    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
 | 
				
			||||||
        for y in 0..self.height() {
 | 
					        for y in 0..self.height() {
 | 
				
			||||||
            for x in 0..self.width() {
 | 
					            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')
 | 
					        f.write_char('\n')
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user