1
0
Fork 0

day(07): use match

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-12-07 10:40:09 +01:00
parent b582bf33d9
commit 1275d5b738
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -88,20 +88,14 @@ impl Hand {
let mut freqs = freqs.values().cloned().collect_vec();
freqs.sort_by_key(|&c| Reverse(c));
if freqs[0] == 5 {
HandType::FiveOfAKind
} else if freqs[0] == 4 {
HandType::FourOfAKind
} else if freqs[0] == 3 && freqs[1] == 2 {
HandType::FullHouse
} else if freqs[0] == 3 {
HandType::ThreeOfAKind
} else if freqs[0] == 2 && freqs[1] == 2 {
HandType::TwoPair
} else if freqs[0] == 2 {
HandType::OnePair
} else {
HandType::HighCard
match freqs[..] {
[5, ..] => HandType::FiveOfAKind,
[4, ..] => HandType::FourOfAKind,
[3, 2, ..] => HandType::FullHouse,
[3, ..] => HandType::ThreeOfAKind,
[2, 2] => HandType::TwoPair,
[2, ..] => HandType::OnePair,
_ => HandType::HighCard,
}
}
@ -113,20 +107,18 @@ impl Hand {
let mut freqs = freqs.values().cloned().collect_vec();
freqs.sort_by_key(|&c| Reverse(c));
if jokers == 5 || freqs[0] + jokers == 5 {
HandType::FiveOfAKind
} else if freqs[0] + jokers == 4 {
HandType::FourOfAKind
} else if freqs[0] + jokers == 3 && freqs[1] == 2 {
HandType::FullHouse
} else if freqs[0] + jokers == 3 {
HandType::ThreeOfAKind
} else if freqs[0] == 2 && freqs[1] == 2 {
HandType::TwoPair
} else if freqs[0] + jokers == 2 {
HandType::OnePair
} else {
HandType::HighCard
if jokers == 5 {
return HandType::FiveOfAKind;
}
match freqs[..] {
[n, ..] if n + jokers == 5 => HandType::FiveOfAKind,
[n, ..] if n + jokers == 4 => HandType::FourOfAKind,
[n, 2, ..] if n + jokers == 3 => HandType::FullHouse,
[n, ..] if n + jokers == 3 => HandType::ThreeOfAKind,
[2, 2, ..] => HandType::TwoPair,
[n, ..] if n + jokers == 2 => HandType::OnePair,
_ => HandType::HighCard,
}
}
}