| about | help | code help+videos | done | prefs |
poker
In the card game poker, a hand consists of five cards and hands are ranked, from highest to lowest, in the following way: (8) Straight Flush: All cards are consecutive values of same suit. (7) Four of a Kind: Four cards of the same value. (6) Full House: Three of a kind and a pair. (5) Flush: All cards of the same suit. (4) Straight: All cards are consecutive values. (3) Three of a Kind: Three cards of the same value. (2) Two Pairs: Two different pairs. (1) One Pair: Two cards of the same value. (0) High Card: Highest value card. (See http://en.wikipedia.org/wiki/List_of_poker_hands .) Within each level, ties go to the highest cards. First the highest cards that are involved in the level, then the remaining cards. For example, if two players both have a pair, then the one that has the highest pair wins (regardless of the other cards). If they both have the same pairs, then the highest of the other cards wins. The cards are valued in the order (lowest to highest): 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace. There is one exception to this ordering: The hand Ace, 2, 3, 4, 5 counts as a straight, but in this case, the Ace is the low card, not the high card. (This problem adapted from Project Euler with small changes to the description.) A hand is represented as a string of five cards separated by spaces, for example "QD AD TH KC 9S", where the first character is the rank (T for 10), and the second character is the suit. The function "poker" is passed a list of hands and should return the winning hand. poker(['QD AD AH KH 9D', 'JS 9H JC KD JD']) → 'JS 9H JC KD JD' poker(['8S 3C 4S TS 7S', '4D 5C 2S 6H 7C']) → '8S 3C 4S TS 7S' poker(['AS 2H 3C 4D 5S', '2S 3D 4C 5D 6S']) → '2S 3D 4C 5D 6S' ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 900 Post-solution available
Copyright Nick Parlante 2017 - privacy