Inspired by this challenge and related to this one.

### Background

Badugi [bæduːɡiː] is a low-ball draw-poker variant.

“A+KYTE”yḲONŒPÇ€ṢṪµ€⁼€Ṁ$A monadic link taking a list of two lists of characters - each being a space separated representation of the hand (e.g. "Ac 2d 4s 3h") returning a list of two numbers identifying the winner(s) with 1 and any loser with 0 - i.e. [1, 0] = left wins; [0, 1] = right wins; [1, 1] = draw. Try it online! or see the test-suite. ### How? ẎŒQȦ;L;Ṗ€Ṣ$ - Link 1, sortKey: list of lists of numbers representing some cards (see Main)
Ẏ           - flatten into a single list of numbers
ŒQ         - distinct sieve (1 at first occurrence of anything, 0 at the rest)
Ȧ        - Any & All? zero if any are 0 or if empty; 1 otherwise (i.e. playable hand?)
L      - length of input (number of cards in the hand)
;       - concatenate
$- last two links as a monad: Ṗ€ - pop each (get just the rank portions) Ṣ - sort (Main's translation & negation of ordinals ensures A>2>3>...>Q>K) ; - concatenate (now we have [isPlayable; nCards; [lowToHighCards]]) “A+KYTE”yḲONŒPÇ€ṢṪµ€⁼€Ṁ$ - Main link: list of lists of characters, hands
µ€     - for €ach of the two hands:
“A+KYTE”                 -   literal list of characters "A+KYTE" (compressing doesn't help - lower case would be “£Ḅṁ⁽>» though -- I'll stick with kyte though it's kind of nice.)
y                -   translate - change As to +s, Ks to Ys and Ts to Es
-               note the ranks are now in ordinal order:
-               +<2<3<4<5<6<7<8<9<E<J<Q<Y
Ḳ               -   split at spaces - split the four cards up
O              -   to ordinals '+'->43, '2'->50, ...
N             -   negate - effectively reverse the ordering
ŒP           -   power-set - get all combinations of 0 to 4 cards inclusive
Ç€         -   call the last link (1) as a monad for €ach such selection
Ṣ        -   sort these keys
Ṫ       -   tail - get (one of) the maximal keys
-                       (the key of a best, playable selection)
Ṁ  -   maximum (the better of the two best, playable selection keys)
⁼€   -   equals? for €ach (1 if the hand is a winner, 0 if not)

# Python 3, 207 204 bytes

lambda i,j:L(h(i))-L(h(j))if L(h(i))!=L(h(j))else(h(i)<h(j))-(h(i)>h(j))
L=len
def h(l):s=set();return[x[0]for x in sorted(y.translate({65:49,75:90,84:65})for y in l)if not(s&set(x)or s.update(*x))][::-1]

Try it online!

Saved 3 bytes thanks to Jonathan Frech

Returns 1 if the first hand wins, -1 if the second hand wins and 0 in case of a draw.

The function h computes a list that represents the hand.

The lambda compares two representations of hand. I think it might be shortened, but I wanted to return only three values and didn't find a simpler way to do comparison.

• You can save two bytes by defining L=len and replacing all other occurrences of lenwith L. Sep 14 '17 at 21:10
• Also, you can probably replace s=set() with s={0} and set(x)&s or with s&set(x)or Sep 14 '17 at 21:13