Another example of the answer to the reference question (http://qiita.com/items/cbc3af152ee3f50a822f) of the study session (http://atnd.org/events/30285) scheduled to be held on 7/6 (Friday). I decided to write in a language that hasn't come out yet, so python.
poka.py
# -*- coding: utf-8 -*-
import re
Q=[ "DASAD10CAHA", "S10HJDJCJSJ",
"S10HAD10DAC10", "HJDJC3SJS3",
"S3S4H3D3DA", "S2HADKCKSK",
"SASJDACJS10", "S2S10H10HKD2",
"CKH10D10H3HJ", "C3D3S10SKS2",
"S3SJDAC10SQ", "C3C9SAS10D2"]
def hand_name( d ):
if d==[1,4]: return '4K'
if d==[2,3]: return 'FH'
if d==[1,1,3]: return '3K'
if d==[1,2,2]: return '2P'
if d==[1,1,1,2]: return '1P'
return '--'
def rank_dist( ranks ):
map={}
for r in ranks:
if r in map:
map[r]+=1
else:
map[r]=1
dist = map.values()
dist.sort()
return dist
p = re.compile( r"[SHDC]([JQKA\d]+)"*5)
for q in Q:
mo=p.match( q )
ranks=sorted( [ mo.group( x+1 ) for x in range(5) ] )
dist=rank_dist( ranks )
print hand_name( dist )
I have almost no experience with python, so I think I can probably write much better. Especially, the rank_dist function feels very stupid.
There was such a freshness as I had to write a return and I wondered if I could omit the parentheses.
The list comprehension notation is the real thrill, so I have to use it.