aoc2020: fix clippy lints

This commit is contained in:
Antoine Martin 2023-12-05 12:49:44 +01:00
parent 0df2dd8dd8
commit 74f2ada129
4 changed files with 7 additions and 11 deletions

View file

@ -286,7 +286,7 @@ impl Program {
} }
fn memory_sum(&self) -> u64 { fn memory_sum(&self) -> u64 {
self.memory.iter().map(|(_, value)| value).sum() self.memory.values().sum()
} }
} }

View file

@ -44,7 +44,6 @@ fn assign_field_positions(
.iter() .iter()
.map(|(&name, field)| { .map(|(&name, field)| {
let possibilities = (0..num_values) let possibilities = (0..num_values)
.into_iter()
.filter(|i| tickets.iter().all(|t| t.valid_field(field, *i))) .filter(|i| tickets.iter().all(|t| t.valid_field(field, *i)))
.collect(); .collect();

View file

@ -307,8 +307,7 @@ impl Image {
image_positions.insert((0, 0), tiles[0].clone()); image_positions.insert((0, 0), tiles[0].clone());
// compute each image position depending on its neighbours // compute each image position depending on its neighbours
while !todo.is_empty() { while let Some(pos) = todo.pop() {
let pos = todo.pop().unwrap();
let tile = &image_positions[&pos]; let tile = &image_positions[&pos];
for (direction, other_tile) in tile.neighbours(tiles) { for (direction, other_tile) in tile.neighbours(tiles) {
@ -339,9 +338,9 @@ impl Image {
const IMAGE_TILE_HEIGHT: usize = TILE_HEIGHT - 2; const IMAGE_TILE_HEIGHT: usize = TILE_HEIGHT - 2;
const IMAGE_TILE_WIDTH: usize = TILE_WIDTH - 2; const IMAGE_TILE_WIDTH: usize = TILE_WIDTH - 2;
let height = *image_positions.iter().map(|((i, _), _)| i).max().unwrap() as usize + 1; let height = *image_positions.iter().map(|((i, _), _)| i).max().unwrap() + 1;
let height = height * IMAGE_TILE_HEIGHT; let height = height * IMAGE_TILE_HEIGHT;
let width = *image_positions.iter().map(|((_, j), _)| j).max().unwrap() as usize + 1; let width = *image_positions.iter().map(|((_, j), _)| j).max().unwrap() + 1;
let width = width * IMAGE_TILE_HEIGHT; let width = width * IMAGE_TILE_HEIGHT;
let mut pixels = Vec::new(); let mut pixels = Vec::new();
@ -352,8 +351,8 @@ impl Image {
} }
for (pos, tile) in image_positions { for (pos, tile) in image_positions {
let begin_i = IMAGE_TILE_HEIGHT * pos.0 as usize; let begin_i = IMAGE_TILE_HEIGHT * pos.0;
let begin_j = IMAGE_TILE_WIDTH * pos.1 as usize; let begin_j = IMAGE_TILE_WIDTH * pos.1;
for i in 0..IMAGE_TILE_HEIGHT { for i in 0..IMAGE_TILE_HEIGHT {
for j in 0..IMAGE_TILE_WIDTH { for j in 0..IMAGE_TILE_WIDTH {

View file

@ -86,9 +86,7 @@ fn part2(input: &str) -> Result<usize> {
let mut seen = HashSet::new(); let mut seen = HashSet::new();
let mut todo: Vec<HexCoordinates> = black_tiles.iter().copied().collect(); let mut todo: Vec<HexCoordinates> = black_tiles.iter().copied().collect();
while !todo.is_empty() { while let Some(tile) = todo.pop() {
let tile = todo.pop().unwrap();
if seen.contains(&tile) { if seen.contains(&tile) {
continue; continue;
} else { } else {