4,494
edits
Miraheze>Marshall No edit summary |
m (Text replacement - " ⊢( *[^∘])" to " ⎕←$1") |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
This article uses [[Dyalog APL]] to rank poker hands using the rules of [ | This article uses [[Dyalog APL]] to rank poker hands using the rules of [[wikipedia:Texas hold 'em|Texas hold 'em]] and other popular poker variants. The function <source lang=apl inline>handrank</source> below transforms a representation of a poker hand into a "rank" array so that the ordering of ranks under [[total array ordering]] is the same as the ordering of the initial poker hands. Poker hands can then by sorted or compared by calling <source lang=apl inline>handrank</source> on each one, then ordering with normal APL functions. | ||
== Dyalog '19 version == | == Dyalog '19 version == | ||
Marshall Lochbaum showed the following code in a presentation (D04: "Tacit Techniques with Dyalog version 18.0 Operators"; video [https://dyalog.tv/Dyalog19/?v=czWC4tjwzOQ here]) at the [https://www.dyalog.com/user-meetings/dyalog19.htm Dyalog '19] user meeting. | [[Marshall Lochbaum]] showed the following code in a presentation (D04: "Tacit Techniques with Dyalog version 18.0 Operators"; video [https://dyalog.tv/Dyalog19/?v=czWC4tjwzOQ here]) at the [https://www.dyalog.com/user-meetings/dyalog19.htm Dyalog '19] user meeting. | ||
<source lang=apl> | <source lang=apl> | ||
handrank←{⊃{((8|@1⊢2-/⍺)⍵∧.=¨1,⊃⍵){(∧/⍺),(2=≢⍵),⍺,⊂⍵[⍒⍵;]⊖⍨⊃⍺},⍨∘≢⌸⍺}/↓⍉⍵[⍒⍵;]} | handrank←{⊃{((8|@1⊢2-/⍺)⍵∧.=¨1,⊃⍵){(∧/⍺),(2=≢⍵),⍺,⊂⍵[⍒⍵;]⊖⍨⊃⍺},⍨∘≢⌸⍺}/↓⍉⍵[⍒⍵;]} | ||
Line 113: | Line 113: | ||
<source lang=apl> | <source lang=apl> | ||
r s ← ↓⍉sort hand 'A♠2♠3♣4♠5♢' | r s ← ↓⍉sort hand 'A♠2♠3♣4♠5♢' | ||
⎕←ranks ← sort {(≢⍵),⍺}⌸ r | |||
1 13 | 1 13 | ||
1 4 | 1 4 | ||
Line 119: | Line 119: | ||
1 2 | 1 2 | ||
1 1 | 1 1 | ||
⎕←sf ← (8|@1⊢2-/r)s∧.=¨1,⊃s | |||
1 0 | 1 0 | ||
</source> | </source> | ||
Line 155: | Line 155: | ||
== Examples == | == Examples == | ||
To test our function, we can try it on the sample hands given in Wikipedia's page on Texas hold 'em [ | To test our function, we can try it on the sample hands given in Wikipedia's page on Texas hold 'em [[wikipedia:Texas hold 'em#Hand_values|here]]. The ranks for each of these hands are shown, as well as a [[grade up]] to demonstrate that they are in ascending order. | ||
<source lang=apl> | <source lang=apl> | ||
hands ← ' '(≠⊆⊢)'A♣4♡7♢K♣2♠ K♣K♡7♢2♣5♠ K♣K♡7♢7♣5♠ K♣K♡K♢7♣5♠ 3♣4♡5♢6♣7♠ K♣Q♣9♣8♣2♣ K♣K♡K♢7♣7♠ K♣K♡K♢K♠5♠ 3♣4♣5♣6♣7♣ T♡J♡Q♡K♡A♡' | hands ← ' '(≠⊆⊢)'A♣4♡7♢K♣2♠ K♣K♡7♢2♣5♠ K♣K♡7♢7♣5♠ K♣K♡K♢7♣5♠ 3♣4♡5♢6♣7♠ K♣Q♣9♣8♣2♣ K♣K♡K♢7♣7♠ K♣K♡K♢K♠5♠ 3♣4♣5♣6♣7♣ T♡J♡Q♡K♡A♡' | ||
Line 227: | Line 227: | ||
1 2 3 4 5 6 7 8 9 10 | 1 2 3 4 5 6 7 8 9 10 | ||
</source> | </source> | ||
[[Category:Examples]][[Category:Dyalog APL examples]] |