clippies
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
use aoc_runner_derive::aoc;
|
||||
use std::io::{BufRead, BufReader, Lines};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
// PROBLEM 1 solution
|
||||
#[aoc(day1, part1)]
|
||||
@@ -16,7 +14,7 @@ pub fn part1(input: &str) -> u64 {
|
||||
let add_val = match sign.as_bytes()[0] {
|
||||
b'R' => num_val,
|
||||
b'L' => mod_val - (num_val % mod_val),
|
||||
c => panic!("Invalid direction {}", c),
|
||||
c => panic!("Invalid direction {c}"),
|
||||
};
|
||||
val = (val + add_val) % mod_val;
|
||||
if val == 0 {
|
||||
@@ -65,7 +63,7 @@ pub fn part2(input: &str) -> i64 {
|
||||
let (new_val, add_pass) = match sign.as_bytes()[0] {
|
||||
b'R' => advance::<100>(val, num_val),
|
||||
b'L' => advance::<100>(val, -num_val),
|
||||
c => panic!("Invalid direction {}", c),
|
||||
c => panic!("Invalid direction {c}"),
|
||||
};
|
||||
val = new_val;
|
||||
pass += add_pass;
|
||||
@@ -77,7 +75,7 @@ pub fn part2(input: &str) -> i64 {
|
||||
mod tests {
|
||||
use crate::day1::*;
|
||||
|
||||
const EXAMPLE: &str = &"L68
|
||||
const EXAMPLE: &str = "L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
use itertools::Itertools;
|
||||
use std::cmp::{max, min};
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
#[aoc_generator(day2)]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
mod day1;
|
||||
mod day2;
|
||||
pub mod day1;
|
||||
|
||||
use aoc_runner_derive::aoc_lib;
|
||||
|
||||
|
||||
@@ -321,7 +321,13 @@ impl<T: Clone + Eq + PartialEq + Debug> Grid<T> {
|
||||
self.data
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find_map(|(pos, val)| if val == haystack { Some(pos as i64) } else { None })
|
||||
.find_map(|(pos, val)| {
|
||||
if val == haystack {
|
||||
Some(pos as i64)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or(-1),
|
||||
)
|
||||
}
|
||||
@@ -330,7 +336,10 @@ impl<T: Clone + Eq + PartialEq + Debug> Grid<T> {
|
||||
}
|
||||
|
||||
pub fn forward_slice<C: AsCoord2d>(&self, start: &C, len: i64) -> Option<&[T]> {
|
||||
let pos = (self.valid_pos(start), self.valid_pos(&(start.x() + len - 1, start.y())));
|
||||
let pos = (
|
||||
self.valid_pos(start),
|
||||
self.valid_pos(&(start.x() + len - 1, start.y())),
|
||||
);
|
||||
match pos {
|
||||
(Some(pos1), Some(pos2)) => Some(&self.data[pos1..pos2 + 1]),
|
||||
_ => None,
|
||||
@@ -406,7 +415,10 @@ impl Display for Grid<u8> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
for y in 0..self.height() {
|
||||
for x in 0..self.width() {
|
||||
f.write_fmt(format_args!("{}", *self.get(&(x as i64, y as i64)).unwrap() as char))?;
|
||||
f.write_fmt(format_args!(
|
||||
"{}",
|
||||
*self.get(&(x as i64, y as i64)).unwrap() as char
|
||||
))?;
|
||||
}
|
||||
f.write_char('\n')?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user