Skip to content

Commit

Permalink
refactor: clippy fix all days
Browse files Browse the repository at this point in the history
  • Loading branch information
JosefKuchar committed Dec 8, 2024
1 parent a687864 commit c15009a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/bin/06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ advent_of_code::solution!(6);

const DIRS: [(isize, isize); 4] = [(-1, 0), (0, 1), (1, 0), (0, -1)];

fn in_bounds(map: &Vec<Vec<char>>, pos: (isize, isize)) -> bool {
fn in_bounds(map: &[Vec<char>], pos: (isize, isize)) -> bool {
pos.0 >= 0 && pos.1 >= 0 && pos.0 < map.len() as isize && pos.1 < map[0].len() as isize
}

fn check_map(map: &Vec<Vec<char>>, start: (isize, isize)) -> (bool, Vec<(isize, isize)>) {
fn check_map(map: &[Vec<char>], start: (isize, isize)) -> (bool, Vec<(isize, isize)>) {
let mut visited: HashSet<(isize, isize)> = HashSet::new();
let mut visited_dir: HashSet<((isize, isize), usize)> = HashSet::new();
let mut dir = 0;
Expand All @@ -22,7 +22,7 @@ fn check_map(map: &Vec<Vec<char>>, start: (isize, isize)) -> (bool, Vec<(isize,
visited_dir.insert((current, dir));
let next = (current.0 + DIRS[dir].0, current.1 + DIRS[dir].1);
if !in_bounds(map, next) {
return (false, visited.iter().map(|x| *x).collect());
return (false, visited.iter().copied().collect());
}
if map[next.0 as usize][next.1 as usize] == '#' {
dir = (dir + 1) % 4;
Expand All @@ -35,9 +35,9 @@ fn check_map(map: &Vec<Vec<char>>, start: (isize, isize)) -> (bool, Vec<(isize,
fn parse_input(input: &str) -> (Vec<Vec<char>>, (isize, isize)) {
let map: Vec<Vec<char>> = input.lines().map(|line| line.chars().collect()).collect();
let mut start: (isize, isize) = (0, 0);
for i in 0..map.len() {
for j in 0..map[i].len() {
if map[i][j] == '^' {
for (i, row) in map.iter().enumerate() {
for (j, cell) in row.iter().enumerate() {
if *cell == '^' {
start = (i as isize, j as isize);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn solve(input: &str, skip: usize) -> Option<u64> {
.multi_cartesian_product()
.any(|c| {
let mut c = c.into_iter();
numbers.iter().map(|x| *x).reduce(|acc, n| {
numbers.iter().copied().reduce(|acc, n| {
let op = c.next().unwrap();
match op {
Operation::Add => acc + n,
Expand Down
10 changes: 5 additions & 5 deletions src/bin/08.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ use std::collections::HashSet;

advent_of_code::solution!(8);

fn in_bounds(map: &Vec<Vec<char>>, pos: (i32, i32)) -> bool {
fn in_bounds(map: &[Vec<char>], pos: (i32, i32)) -> bool {
pos.0 >= 0 && pos.1 >= 0 && pos.0 < map.len() as i32 && pos.1 < map[0].len() as i32
}

pub fn solve<R: IntoIterator<Item = i32> + Clone>(input: &str, range: R) -> Option<u32> {
let map: Vec<Vec<char>> = input.lines().map(|line| line.chars().collect()).collect();
let mut antennas: Vec<((usize, usize), char)> = Vec::new();
for i in 0..map.len() {
for j in 0..map[i].len() {
if map[i][j] != '.' {
antennas.push(((i, j), map[i][j]));
for (i, row) in map.iter().enumerate() {
for (j, cell) in row.iter().enumerate() {
if *cell != '.' {
antennas.push(((i, j), *cell));
}
}
}
Expand Down

0 comments on commit c15009a

Please sign in to comment.