Fixed clippy warnings
This commit is contained in:
parent
1d0154122b
commit
a3ce12a80b
8 changed files with 18 additions and 31 deletions
|
@ -21,12 +21,9 @@ fn min_location_from_given_single_seeds(
|
||||||
let mut current_seed = *next_seed;
|
let mut current_seed = *next_seed;
|
||||||
for next_layer in layers {
|
for next_layer in layers {
|
||||||
for next_mapping in next_layer {
|
for next_mapping in next_layer {
|
||||||
match next_mapping.map_point(current_seed) {
|
if let Some(found_mapping) = next_mapping.map_point(current_seed) {
|
||||||
Some(found_mapping) => {
|
current_seed = found_mapping;
|
||||||
current_seed = found_mapping;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +116,6 @@ fn combine_single_to_ranges_for_seeds(single_seeds: &[UnsignedNumber]) -> Vec<Se
|
||||||
assert!(single_seeds.len() % 2 == 0);
|
assert!(single_seeds.len() % 2 == 0);
|
||||||
single_seeds
|
single_seeds
|
||||||
.chunks(2)
|
.chunks(2)
|
||||||
.into_iter()
|
|
||||||
.map(|array| match array {
|
.map(|array| match array {
|
||||||
[start, end] => {
|
[start, end] => {
|
||||||
let start = *start;
|
let start = *start;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::usize;
|
|
||||||
|
|
||||||
mod parsing;
|
mod parsing;
|
||||||
mod race_record;
|
mod race_record;
|
||||||
|
|
||||||
|
@ -11,7 +9,6 @@ pub fn solve_task_1(input: &str) -> String {
|
||||||
|
|
||||||
for next_record in parsed {
|
for next_record in parsed {
|
||||||
how_many_times_won *= all_rounds_of_durations(next_record.time())
|
how_many_times_won *= all_rounds_of_durations(next_record.time())
|
||||||
.into_iter()
|
|
||||||
.filter(|&distance| distance > next_record.reached_distance())
|
.filter(|&distance| distance > next_record.reached_distance())
|
||||||
.count() as NumericValue;
|
.count() as NumericValue;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +26,6 @@ pub fn solve_task_2(input: &str) -> String {
|
||||||
|
|
||||||
const FIRST_CYCLE_NO_DISTANCE: usize = 1;
|
const FIRST_CYCLE_NO_DISTANCE: usize = 1;
|
||||||
for (index, next_distance) in all_rounds_of_durations(parsed.time())
|
for (index, next_distance) in all_rounds_of_durations(parsed.time())
|
||||||
.into_iter()
|
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.skip(FIRST_CYCLE_NO_DISTANCE)
|
.skip(FIRST_CYCLE_NO_DISTANCE)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,7 +43,7 @@ fn categorize_and_sort_with_a_joker(parsed: Vec<DealtHand>, joker: char) -> Vec<
|
||||||
|
|
||||||
fn calc_total_winning(sorted: &[CategorizedHand]) -> usize {
|
fn calc_total_winning(sorted: &[CategorizedHand]) -> usize {
|
||||||
sorted
|
sorted
|
||||||
.into_iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, hand)| {
|
.map(|(index, hand)| {
|
||||||
let rank = index.saturating_add(1);
|
let rank = index.saturating_add(1);
|
||||||
|
|
|
@ -2,7 +2,6 @@ mod joker_ordered;
|
||||||
pub use joker_ordered::JokerOrdered;
|
pub use joker_ordered::JokerOrdered;
|
||||||
|
|
||||||
use crate::day7::second_ordering;
|
use crate::day7::second_ordering;
|
||||||
use std::usize;
|
|
||||||
|
|
||||||
use super::{dealt_hand::DealtHand, hand_kind::HandKind, second_ordering::StrengthOfSymbols};
|
use super::{dealt_hand::DealtHand, hand_kind::HandKind, second_ordering::StrengthOfSymbols};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{str::FromStr, usize};
|
use std::str::FromStr;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|
|
@ -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 current_kind = choose_kind_from(&duplicated_counted);
|
||||||
let mut joker_count = get_joker_count(joker_char, characters);
|
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 {
|
impl From<&'_ str> for HandKind {
|
||||||
fn from(value: &'_ str) -> Self {
|
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)
|
choose_kind_from(&duplicated_counted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,13 +78,13 @@ fn calc_duplicate_counted(
|
||||||
if on_consider_next_char(next_char) {
|
if on_consider_next_char(next_char) {
|
||||||
count_of_same
|
count_of_same
|
||||||
.entry(next_char)
|
.entry(next_char)
|
||||||
.and_modify(|count| *count = *count + 1)
|
.and_modify(|count| *count += 1)
|
||||||
.or_insert(FIRST_ENCOUNTERED);
|
.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.sort_by_key(|&count| Reverse(count));
|
||||||
to_sort
|
to_sort
|
||||||
}
|
}
|
||||||
|
@ -119,9 +119,9 @@ fn choose_kind_from(to_choose_from: &[usize]) -> HandKind {
|
||||||
Some(kind)
|
Some(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
calc_kind(&to_choose_from).unwrap_or_else(|| {
|
calc_kind(to_choose_from).unwrap_or_else(|| {
|
||||||
let default_value = HandKind::default();
|
|
||||||
default_value
|
HandKind::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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';
|
pub const JOKER: char = 'J';
|
||||||
static LETTERS_WITHOUT_JOKER: &[char] = &['T', 'Q', 'K', 'A'];
|
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>;
|
pub type StrengthOfSymbols = HashMap<char, usize>;
|
||||||
|
|
||||||
fn numbers_in_chars() -> impl Iterator<Item = char> {
|
fn numbers_in_chars() -> impl Iterator<Item = char> {
|
||||||
NUMBERS
|
NUMBERS.map(|number| std::char::from_digit(number, 10).unwrap())
|
||||||
.into_iter()
|
|
||||||
.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.
|
//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.
|
//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(|| {
|
pub static LABEL_ORDERING: LazyLock<StrengthOfSymbols> = LazyLock::new(|| {
|
||||||
numbers_in_chars()
|
numbers_in_chars()
|
||||||
.chain(LETTERS.into_iter().copied())
|
.chain(LETTERS.iter().copied())
|
||||||
.into_iter()
|
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, character)| (character, index))
|
.map(|(index, character)| (character, index))
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -27,8 +24,7 @@ pub static LABEL_ORDERING: LazyLock<StrengthOfSymbols> = LazyLock::new(|| {
|
||||||
pub static LABEL_ORDERING_WITH_JOKER: LazyLock<StrengthOfSymbols> = LazyLock::new(|| {
|
pub static LABEL_ORDERING_WITH_JOKER: LazyLock<StrengthOfSymbols> = LazyLock::new(|| {
|
||||||
std::iter::once(JOKER)
|
std::iter::once(JOKER)
|
||||||
.chain(numbers_in_chars())
|
.chain(numbers_in_chars())
|
||||||
.chain(LETTERS_WITHOUT_JOKER.into_iter().copied())
|
.chain(LETTERS_WITHOUT_JOKER.iter().copied())
|
||||||
.into_iter()
|
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, character)| (character, index))
|
.map(|(index, character)| (character, index))
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -47,7 +43,7 @@ pub fn compare_along_str(
|
||||||
.get(&right_char)
|
.get(&right_char)
|
||||||
.unwrap_or_else(|| panic!("right char ({}) is not valid", 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;
|
let found_difference = current_ordering != Ordering::Equal;
|
||||||
if found_difference {
|
if found_difference {
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub fn blocks_of_lines_seperated_by<'a>(
|
||||||
let mut current_block = Vec::new();
|
let mut current_block = Vec::new();
|
||||||
let mut lines = input.lines();
|
let mut lines = input.lines();
|
||||||
std::iter::from_fn(move || {
|
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 on_skip(next_line) {
|
||||||
if !current_block.is_empty() {
|
if !current_block.is_empty() {
|
||||||
let to_return = std::mem::take(&mut current_block);
|
let to_return = std::mem::take(&mut current_block);
|
||||||
|
|
Loading…
Add table
Reference in a new issue