# Rank poker High Card hands [closed]

In the poker game there are 1277 unique 'High Card' ranks. It's 1287 (13 over 5) if we include all straights.

The challenge is to write a function which returns an integer value corresponding to the rank of each 'High Card' poker combination including all straights. Possible cards are(in ascending order): '23456789TJQKA'

23456 -> 1
23457 -> 2
23467 -> 3
23567 -> 4
....
8JQKA -> 1285
9JQKA -> 1286
TJQKA -> 1287

• Can we take a hand as ["10", "J", "Q", "K", "A"]
– Tbw
Mar 14 at 18:23
• isn't 23456 a straight rather a high card hand? Mar 14 at 19:33
• There are indeed 13 choose 5 = 13! / 5! / 8! = 1287 poker hands with no repeated cards (ignoring suits.) 10 of these are straights (Ace low through 10 low) . Looks like straights are not considered in the rules of this question. Mar 14 at 19:46
• How does it sort?
– l4m2
Mar 14 at 20:47
• I said that we can include straights for simplicity Mar 15 at 7:57

# Jelly, 20 bytes

9RḊṾ€;“TJQKA”Ṛœc5ṚiṚ


Try It Online!

### Explanation

9RḊṾ€;“TJQKA”Ṛœc5ṚiṚ    Main Link
9R                      [1, ..., 9]
Ḋ                     Dequeue: [2, ..., 9]
Ṿ€                   Un-Eval Each: "23456789"
;“TJQKA”           Append: "23456789TJQKA"
Ṛ          Reverse: "AKQJT98765432"
œc5       Combinations of length 5
Ṛ      Reverse
iṚ    Find the index of the reversed input


This isn't quite lexicographical order, it's sort of the opposite, so we must reverse the generation string, the combination list itself, and the input to account for this.

# JavaScript (Node.js), 71 bytes

x=>(y=g=(a,i=13)=>a[4]?y|=a==x:i&&g('23456789TJQKA'[--i]+a,i)+g(a,i))


Try it online!

x=>(             // Input
y=             // Init y to not-a-number (behaves as 0)
g=             // and define a function to recurse
(a,i=13)=>     // a is current string,
// i is possible chosen characters left
a[4]?        // current string length 5
y|=a==x    // set y to 1 if a==x, otherwise remain
// then returns y
// This counts how many times called
// after a==x
:            // otherwise(length is not 5)
i&&        // if no characters left, return 0
g('23456789TJQKA'[--i]
+a,i)+ // First count if the next char is chosen
g(a,i)     // then if it isn't chosen
// Therefore, if all characters after X
// both appear or both don't appear in
// string P and Q, and P includes X
// while Q doesn't, then P is executed
// earlier than Q.
)              // Calls g with [''], which behaves
// same as empty string.


• What do them last two backticks do? Mar 15 at 12:17
• @Ziarek Calls the function with argument [""]
– l4m2
Mar 15 at 12:20
• I'm trying to understand this algorithm and I have to say - I'm struggling. I will blame it on JS not being my primary language ;) . Would you be able to provide a non lambda equivalent if possible? Mar 15 at 13:03
• @Ziarek Maybe function f(input){count=status=0;for(i of ['TJQKA','9JQKA',...,'23456']){if(i==input)status=1;count+=status;}return count;}?
– l4m2
Mar 15 at 13:18

# JavaScript (ES6), 105 bytes

Expects an array of characters.

a=>(g=a=>a.some(v=>(i++&&x+1)<(x=v),i=0)?1+g(a.map(v=>i?x-i--:v)):1)(a.map(c=>"23456789TJQKA".search(c)))


Try it online!