#178
Best Hand
 

Difficulty:Hard
Topics:strings game


Following on from Recognize Playing Cards, determine the best poker hand that can be made with five cards. The hand rankings are listed below for your convenience.

  1. Straight flush: All cards in the same suit, and in sequence
  2. Four of a kind: Four of the cards have the same rank
  3. Full House: Three cards of one rank, the other two of another rank
  4. Flush: All cards in the same suit
  5. Straight: All cards in sequence (aces can be high or low, but not both at once)
  6. Three of a kind: Three of the cards have the same rank
  7. Two pair: Two pairs of cards have the same rank
  8. Pair: Two cards have the same rank
  9. High card: None of the above conditions are met

test not run
(= :high-card (__ ["HA" "D2" "H3" "C9" "DJ"]))
test not run
(= :pair (__ ["HA" "HQ" "SJ" "DA" "HT"]))
test not run
(= :two-pair (__ ["HA" "DA" "HQ" "SQ" "HT"]))
test not run
(= :three-of-a-kind (__ ["HA" "DA" "CA" "HJ" "HT"]))
test not run
(= :straight (__ ["HA" "DK" "HQ" "HJ" "HT"]))
test not run
(= :straight (__ ["HA" "H2" "S3" "D4" "C5"]))
test not run
(= :flush (__ ["HA" "HK" "H2" "H4" "HT"]))
test not run
(= :full-house (__ ["HA" "DA" "CA" "HJ" "DJ"]))
test not run
(= :four-of-a-kind (__ ["HA" "DA" "CA" "SA" "DJ"]))
test not run
(= :straight-flush (__ ["HA" "HK" "HQ" "HJ" "HT"]))


Code which fills in the blank: