diff --git a/crates/solutions/src/day5.rs b/crates/solutions/src/day5.rs index 562282d..722de5f 100644 --- a/crates/solutions/src/day5.rs +++ b/crates/solutions/src/day5.rs @@ -21,12 +21,9 @@ 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) => { - current_seed = found_mapping; - break; - } - None => (), + if let Some(found_mapping) = next_mapping.map_point(current_seed) { + current_seed = found_mapping; + break; } } } @@ -119,7 +116,6 @@ fn combine_single_to_ranges_for_seeds(single_seeds: &[UnsignedNumber]) -> Vec { let start = *start; diff --git a/crates/solutions/src/day6.rs b/crates/solutions/src/day6.rs index 9d585a9..92b5c87 100644 --- a/crates/solutions/src/day6.rs +++ b/crates/solutions/src/day6.rs @@ -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) { diff --git a/crates/solutions/src/day7.rs b/crates/solutions/src/day7.rs index 806b182..c50d5bf 100644 --- a/crates/solutions/src/day7.rs +++ b/crates/solutions/src/day7.rs @@ -43,7 +43,7 @@ fn categorize_and_sort_with_a_joker(parsed: Vec, joker: char) -> Vec< fn calc_total_winning(sorted: &[CategorizedHand]) -> usize { sorted - .into_iter() + .iter() .enumerate() .map(|(index, hand)| { let rank = index.saturating_add(1); diff --git a/crates/solutions/src/day7/categorized_hand.rs b/crates/solutions/src/day7/categorized_hand.rs index 1cfe782..6c94d4c 100644 --- a/crates/solutions/src/day7/categorized_hand.rs +++ b/crates/solutions/src/day7/categorized_hand.rs @@ -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}; diff --git a/crates/solutions/src/day7/dealt_hand.rs b/crates/solutions/src/day7/dealt_hand.rs index a21d7ca..2cb1322 100644 --- a/crates/solutions/src/day7/dealt_hand.rs +++ b/crates/solutions/src/day7/dealt_hand.rs @@ -1,4 +1,4 @@ -use std::{str::FromStr, usize}; +use std::str::FromStr; use thiserror::Error; diff --git a/crates/solutions/src/day7/hand_kind.rs b/crates/solutions/src/day7/hand_kind.rs index f627743..3858c54 100644 --- a/crates/solutions/src/day7/hand_kind.rs +++ b/crates/solutions/src/day7/hand_kind.rs @@ -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 = count_of_same.into_iter().map(|(_, count)| count).collect(); + let mut to_sort: Vec = 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() }) } diff --git a/crates/solutions/src/day7/second_ordering.rs b/crates/solutions/src/day7/second_ordering.rs index 7274835..353d66d 100644 --- a/crates/solutions/src/day7/second_ordering.rs +++ b/crates/solutions/src/day7/second_ordering.rs @@ -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 = 0..=9; pub type StrengthOfSymbols = HashMap; fn numbers_in_chars() -> impl Iterator { - 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 = 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 = LazyLock::new(|| { pub static LABEL_ORDERING_WITH_JOKER: LazyLock = 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 { diff --git a/crates/solutions/src/utils/parsing.rs b/crates/solutions/src/utils/parsing.rs index faabf54..ebcca62 100644 --- a/crates/solutions/src/utils/parsing.rs +++ b/crates/solutions/src/utils/parsing.rs @@ -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);