day(07): use match
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
b582bf33d9
commit
1275d5b738
1 changed files with 20 additions and 28 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue