2024: clippies
This commit is contained in:
7 files changed
+69
-41
No files matched your search
+7
-4
@@ -12,11 +12,12 @@ struct LockPile {
|
||||
locks: Vec<Vec<usize>>,
|
||||
}
|
||||
|
||||
fn parse_grid(lines: &Vec<&str>) -> (LockKey, Vec<usize>) {
|
||||
fn parse_grid(lines: &[&str]) -> (LockKey, Vec<usize>) {
|
||||
assert_eq!(lines.len(), 7);
|
||||
if lines[0].chars().all(|c| c == '#') {
|
||||
// lock
|
||||
let mut pins = vec![0; 5];
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
for row in 1..lines.len() {
|
||||
let row_s = lines[row];
|
||||
for i in 0..row_s.len() {
|
||||
@@ -29,8 +30,10 @@ fn parse_grid(lines: &Vec<&str>) -> (LockKey, Vec<usize>) {
|
||||
} else if lines[6].chars().all(|c| c == '#') {
|
||||
// key
|
||||
let mut pins = vec![5; 5];
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
for row in (1..lines.len()).rev() {
|
||||
let row_s = lines[row];
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
for i in 0..row_s.len() {
|
||||
if row_s.chars().nth(i) == Some('#') {
|
||||
pins[i] = 6 - row
|
||||
@@ -48,7 +51,7 @@ fn parse(input: &str) -> LockPile {
|
||||
let mut keys = Vec::new();
|
||||
let mut accum: Vec<&str> = Vec::new();
|
||||
for line in input.lines() {
|
||||
if line == "" {
|
||||
if line.is_empty() {
|
||||
let (lk, pins) = parse_grid(&accum);
|
||||
match lk {
|
||||
LockKey::Lock => locks.push(pins),
|
||||
@@ -59,7 +62,7 @@ fn parse(input: &str) -> LockPile {
|
||||
accum.push(line);
|
||||
}
|
||||
}
|
||||
if accum.len() != 0 {
|
||||
if !accum.is_empty() {
|
||||
let (lk, pins) = parse_grid(&accum);
|
||||
match lk {
|
||||
LockKey::Lock => locks.push(pins),
|
||||
@@ -69,7 +72,7 @@ fn parse(input: &str) -> LockPile {
|
||||
LockPile { keys, locks }
|
||||
}
|
||||
|
||||
fn test_lock_key(lock: &Vec<usize>, key: &Vec<usize>) -> bool {
|
||||
fn test_lock_key(lock: &[usize], key: &[usize]) -> bool {
|
||||
!lock.iter().zip(key.iter()).any(|(lp, kp)| lp + kp > 5)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user