refactor: rename variable
This commit is contained in:
parent
faad5beb77
commit
8499d4e34d
13
src/day07.rs
13
src/day07.rs
@ -1,8 +1,5 @@
|
|||||||
use std::cmp::Ordering;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
use std::panic::panic_any;
|
|
||||||
use std::sync::mpsc::TrySendError::Full;
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
@ -21,7 +18,7 @@ pub enum Card {
|
|||||||
N4 = 12,
|
N4 = 12,
|
||||||
N3 = 13,
|
N3 = 13,
|
||||||
N2 = 14,
|
N2 = 14,
|
||||||
JOKER_2 = 15,
|
Joker = 15,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -72,7 +69,7 @@ impl From<Vec<Card>> for Hand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let key = cards.keys()
|
let key = cards.keys()
|
||||||
.filter(|k| k.to_string() != "JOKER_2")
|
.filter(|k| k.to_string() != "Joker")
|
||||||
.map(|k| (k, cards[k]))
|
.map(|k| (k, cards[k]))
|
||||||
.max_by(|(_, v1), (_, v2)| Ord::cmp(v1, v2));
|
.max_by(|(_, v1), (_, v2)| Ord::cmp(v1, v2));
|
||||||
|
|
||||||
@ -81,9 +78,9 @@ impl From<Vec<Card>> for Hand {
|
|||||||
}
|
}
|
||||||
let key = key.unwrap().0.to_owned();
|
let key = key.unwrap().0.to_owned();
|
||||||
|
|
||||||
let joker = cards.get("JOKER_2").unwrap_or(&0).clone();
|
let joker = cards.get("Joker").unwrap_or(&0).clone();
|
||||||
*cards.entry(key).or_default() += joker;
|
*cards.entry(key).or_default() += joker;
|
||||||
cards.remove("JOKER_2");
|
cards.remove("Joker");
|
||||||
|
|
||||||
|
|
||||||
match cards.values().len() {
|
match cards.values().len() {
|
||||||
@ -147,7 +144,7 @@ fn solve_02(content: &str) -> anyhow::Result<usize> {
|
|||||||
.map(|(hand, bid)| (hand.chars().map(|c| {
|
.map(|(hand, bid)| (hand.chars().map(|c| {
|
||||||
let mut c = Card::from(c);
|
let mut c = Card::from(c);
|
||||||
if c == Card::J {
|
if c == Card::J {
|
||||||
c = Card::JOKER_2;
|
c = Card::Joker;
|
||||||
}
|
}
|
||||||
|
|
||||||
c
|
c
|
||||||
|
Loading…
Reference in New Issue
Block a user