Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Texas Referee by Alejen
import itertools as it
RANKS = "23456789TJQKA"
SUITS = "scdh"
nu=lambda c:RANKS.index(c[0])
co=lambda c:SUITS.index(c[1])
inter=lambda L:(len(L)>1 and [k for k in inter(L[1:]) if k in L[0]]) or (len(L)==1 and L[0]) or []
ks=lambda x:(-nu(x),-co(x))
f=lambda a,b:list(filter(a,b))
m=lambda a,b:list(map(a,b))
COND = [lambda x,l,A:nu(x)==nu(l[0]),
lambda x,l,A:co(x)==co(l[0]),
lambda x,l,A:len(f(lambda k:nu(x) in k,A))>0 and nu(x) not in [nu(a) for a in l]]
HANDS = [([0],[2]),([0],[2,2]),([0],[3]),([2],[5]),([1],[5]),([0],[3,2]),([0],[4]),([1,2],[5])]
def add(c,l,L,cond):
i=len(list(it.takewhile(lambda x:c in x or not cond(c,x,(x!=[] and f(lambda y:len(y)>4,[inter([m(nu,L),list(range(y-4,y+1))]) for y in range(nu(x[0]),nu(x[0])+5)])) or []),l)))
(i==len(l) and l.append([c])==None) or l[i].append(c)
def texas_referee(s):
L=[[],[],[]]
l=sorted(s.split(','),key=ks)
list(it.starmap(lambda k,i:add(k,L[i],l,COND[i]),it.product(l,[0,1,2])))
r=[]
for k in HANDS:
t,i=inter([L[i] for i in k[0]])[:],0
K=k[1][:]
while i
Aug. 11, 2016