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();
|
let mut freqs = freqs.values().cloned().collect_vec();
|
||||||
freqs.sort_by_key(|&c| Reverse(c));
|
freqs.sort_by_key(|&c| Reverse(c));
|
||||||
|
|
||||||
if freqs[0] == 5 {
|
match freqs[..] {
|
||||||
HandType::FiveOfAKind
|
[5, ..] => HandType::FiveOfAKind,
|
||||||
} else if freqs[0] == 4 {
|
[4, ..] => HandType::FourOfAKind,
|
||||||
HandType::FourOfAKind
|
[3, 2, ..] => HandType::FullHouse,
|
||||||
} else if freqs[0] == 3 && freqs[1] == 2 {
|
[3, ..] => HandType::ThreeOfAKind,
|
||||||
HandType::FullHouse
|
[2, 2] => HandType::TwoPair,
|
||||||
} else if freqs[0] == 3 {
|
[2, ..] => HandType::OnePair,
|
||||||
HandType::ThreeOfAKind
|
_ => HandType::HighCard,
|
||||||
} else if freqs[0] == 2 && freqs[1] == 2 {
|
|
||||||
HandType::TwoPair
|
|
||||||
} else if freqs[0] == 2 {
|
|
||||||
HandType::OnePair
|
|
||||||
} else {
|
|
||||||
HandType::HighCard
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,20 +107,18 @@ impl Hand {
|
||||||
let mut freqs = freqs.values().cloned().collect_vec();
|
let mut freqs = freqs.values().cloned().collect_vec();
|
||||||
freqs.sort_by_key(|&c| Reverse(c));
|
freqs.sort_by_key(|&c| Reverse(c));
|
||||||
|
|
||||||
if jokers == 5 || freqs[0] + jokers == 5 {
|
if jokers == 5 {
|
||||||
HandType::FiveOfAKind
|
return HandType::FiveOfAKind;
|
||||||
} else if freqs[0] + jokers == 4 {
|
}
|
||||||
HandType::FourOfAKind
|
|
||||||
} else if freqs[0] + jokers == 3 && freqs[1] == 2 {
|
match freqs[..] {
|
||||||
HandType::FullHouse
|
[n, ..] if n + jokers == 5 => HandType::FiveOfAKind,
|
||||||
} else if freqs[0] + jokers == 3 {
|
[n, ..] if n + jokers == 4 => HandType::FourOfAKind,
|
||||||
HandType::ThreeOfAKind
|
[n, 2, ..] if n + jokers == 3 => HandType::FullHouse,
|
||||||
} else if freqs[0] == 2 && freqs[1] == 2 {
|
[n, ..] if n + jokers == 3 => HandType::ThreeOfAKind,
|
||||||
HandType::TwoPair
|
[2, 2, ..] => HandType::TwoPair,
|
||||||
} else if freqs[0] + jokers == 2 {
|
[n, ..] if n + jokers == 2 => HandType::OnePair,
|
||||||
HandType::OnePair
|
_ => HandType::HighCard,
|
||||||
} else {
|
|
||||||
HandType::HighCard
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue