Fixed clippy warnings

This commit is contained in:
BoolPurist 2024-08-30 06:03:08 +02:00
parent 1d0154122b
commit a3ce12a80b
8 changed files with 18 additions and 31 deletions

View file

@ -21,13 +21,10 @@ fn min_location_from_given_single_seeds(
let mut current_seed = *next_seed;
for next_layer in layers {
for next_mapping in next_layer {
match next_mapping.map_point(current_seed) {
Some(found_mapping) => {
if let Some(found_mapping) = next_mapping.map_point(current_seed) {
current_seed = found_mapping;
break;
}
None => (),
}
}
}
min = current_seed.min(min);
@ -119,7 +116,6 @@ fn combine_single_to_ranges_for_seeds(single_seeds: &[UnsignedNumber]) -> Vec<Se
assert!(single_seeds.len() % 2 == 0);
single_seeds
.chunks(2)
.into_iter()
.map(|array| match array {
[start, end] => {
let start = *start;

View file

@ -1,5 +1,3 @@
use std::usize;
mod parsing;
mod race_record;
@ -11,7 +9,6 @@ pub fn solve_task_1(input: &str) -> String {
for next_record in parsed {
how_many_times_won *= all_rounds_of_durations(next_record.time())
.into_iter()
.filter(|&distance| distance > next_record.reached_distance())
.count() as NumericValue;
}
@ -29,7 +26,6 @@ pub fn solve_task_2(input: &str) -> String {
const FIRST_CYCLE_NO_DISTANCE: usize = 1;
for (index, next_distance) in all_rounds_of_durations(parsed.time())
.into_iter()
.enumerate()
.skip(FIRST_CYCLE_NO_DISTANCE)
{

View file

@ -43,7 +43,7 @@ fn categorize_and_sort_with_a_joker(parsed: Vec<DealtHand>, joker: char) -> Vec<
fn calc_total_winning(sorted: &[CategorizedHand]) -> usize {
sorted
.into_iter()
.iter()
.enumerate()
.map(|(index, hand)| {
let rank = index.saturating_add(1);

View file

@ -2,7 +2,6 @@ mod joker_ordered;
pub use joker_ordered::JokerOrdered;
use crate::day7::second_ordering;
use std::usize;
use super::{dealt_hand::DealtHand, hand_kind::HandKind, second_ordering::StrengthOfSymbols};

View file

@ -1,4 +1,4 @@
use std::{str::FromStr, usize};
use std::str::FromStr;
use thiserror::Error;

View file

@ -42,7 +42,7 @@ impl From<(&'_ str, char)> for HandKind {
}
}
let duplicated_counted = calc_duplicate_counted(&characters, |next| next != joker_char);
let duplicated_counted = calc_duplicate_counted(characters, |next| next != joker_char);
let mut current_kind = choose_kind_from(&duplicated_counted);
let mut joker_count = get_joker_count(joker_char, characters);
@ -61,7 +61,7 @@ impl From<(&'_ str, char)> for HandKind {
impl From<&'_ str> for HandKind {
fn from(value: &'_ str) -> Self {
let duplicated_counted = calc_duplicate_counted(&value, |_| true);
let duplicated_counted = calc_duplicate_counted(value, |_| true);
choose_kind_from(&duplicated_counted)
}
}
@ -78,13 +78,13 @@ fn calc_duplicate_counted(
if on_consider_next_char(next_char) {
count_of_same
.entry(next_char)
.and_modify(|count| *count = *count + 1)
.and_modify(|count| *count += 1)
.or_insert(FIRST_ENCOUNTERED);
}
}
{
let mut to_sort: Vec<usize> = count_of_same.into_iter().map(|(_, count)| count).collect();
let mut to_sort: Vec<usize> = count_of_same.into_values().collect();
to_sort.sort_by_key(|&count| Reverse(count));
to_sort
}
@ -119,9 +119,9 @@ fn choose_kind_from(to_choose_from: &[usize]) -> HandKind {
Some(kind)
}
calc_kind(&to_choose_from).unwrap_or_else(|| {
let default_value = HandKind::default();
default_value
calc_kind(to_choose_from).unwrap_or_else(|| {
HandKind::default()
})
}

View file

@ -1,4 +1,4 @@
use std::{cmp::Ordering, collections::HashMap, ops::RangeInclusive, sync::LazyLock, usize};
use std::{cmp::Ordering, collections::HashMap, ops::RangeInclusive, sync::LazyLock};
pub const JOKER: char = 'J';
static LETTERS_WITHOUT_JOKER: &[char] = &['T', 'Q', 'K', 'A'];
@ -8,17 +8,14 @@ const NUMBERS: RangeInclusive<u32> = 0..=9;
pub type StrengthOfSymbols = HashMap<char, usize>;
fn numbers_in_chars() -> impl Iterator<Item = char> {
NUMBERS
.into_iter()
.map(|number| std::char::from_digit(number, 10).unwrap())
NUMBERS.map(|number| std::char::from_digit(number, 10).unwrap())
}
//A hand consists of five cards labeled one of A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, or 2.
//The relative strength of each card follows this order, where A is the highest and 2 is the lowest.
pub static LABEL_ORDERING: LazyLock<StrengthOfSymbols> = LazyLock::new(|| {
numbers_in_chars()
.chain(LETTERS.into_iter().copied())
.into_iter()
.chain(LETTERS.iter().copied())
.enumerate()
.map(|(index, character)| (character, index))
.collect()
@ -27,8 +24,7 @@ pub static LABEL_ORDERING: LazyLock<StrengthOfSymbols> = LazyLock::new(|| {
pub static LABEL_ORDERING_WITH_JOKER: LazyLock<StrengthOfSymbols> = LazyLock::new(|| {
std::iter::once(JOKER)
.chain(numbers_in_chars())
.chain(LETTERS_WITHOUT_JOKER.into_iter().copied())
.into_iter()
.chain(LETTERS_WITHOUT_JOKER.iter().copied())
.enumerate()
.map(|(index, character)| (character, index))
.collect()
@ -47,7 +43,7 @@ pub fn compare_along_str(
.get(&right_char)
.unwrap_or_else(|| panic!("right char ({}) is not valid", right_char));
let current_ordering = left_rank_value.cmp(&right_rank_value);
let current_ordering = left_rank_value.cmp(right_rank_value);
let found_difference = current_ordering != Ordering::Equal;
if found_difference {

View file

@ -5,7 +5,7 @@ pub fn blocks_of_lines_seperated_by<'a>(
let mut current_block = Vec::new();
let mut lines = input.lines();
std::iter::from_fn(move || {
while let Some(next_line) = lines.next() {
for next_line in lines.by_ref() {
if on_skip(next_line) {
if !current_block.is_empty() {
let to_return = std::mem::take(&mut current_block);