Poker hand analyser: Difference between revisions
Content deleted Content added
→{{header|REXX}}: changed the order of WHENs to reflect the hierarchy of poker hands. -- ~~~~ |
m formatting |
||
Line 2:
Create a program to parse a single 5 card poker hand and rank it according to this [[wp:List_of_poker_hands|list of poker hands]].
A poker hand is specified as a space separated list of 5 playing cards. Each input card has two characters indicating face and suit. For example '''2d''' (two of diamonds).
: Faces are: '''a''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''', '''10''', '''j''', '''q''', '''k'''
: Suits are: '''h''' (hearts), '''d''' (diamonds), '''c''' (clubs), and '''s''' (spades), or alternatively the unicode card-suit characters: ♥ ♦ ♣ ♠
Duplicate cards are illegal.
Line 24:
For extra credit:
::*
::*
::*
Examples:
2♥ 2♦ 2♣ k♣ q♦: three-of-a-kind
Line 154:
!! 'invalid';
say "$_: $rank";
}</lang>▼
{{out}}
▲</lang>
2♥ 2♦ 2♣ k♣ q♦: three-of-a-kind
2♥ 5♥ 7♦ 8♣ 9♠: high-card
Line 305 ⟶ 302:
return hand
if __name__ == '__main__':
Line 322 ⟶ 318:
r = rank(cards)
print("%-18r %-15s %r" % (cards, r[0], r[1]))</lang>
{{out}}
<pre>HAND CATEGORY TIE-BREAKER
Line 453 ⟶ 448:
===version 2===
This REXX version supports:
<lang rexx>/*REXX program analyzes an N-card poker hand, displays what the hand is.*/
parse arg iFID .; if iFID=='' then iFID='POKERHAN.DAT'
Line 493 ⟶ 488:
otherwise return 'high-card'
end /*select*/</lang>
Programming note:
<lang rexx>pairs=13-length(space(translate(pips,,2),0)) /*count # of 2's in PIPS.*/</lang>
'''input file''':
Line 527 ⟶ 522:
===version 3 (with jokers)===
This REXX version has three additional features:
<lang rexx>/*REXX program analyzes an N-card poker hand, displays what the hand is.*/
/*─────────────────────────────── poker hands may contain up to 2 jokers*/
Line 587 ⟶ 582:
otherwise return 'high-card'
end /*select*/</lang>
Programming note:
'''input file''':
<pre>
|