Compare two poker hands Challenge:

Given two five-card hands, determine which one wins by the standard ranking of poker hands.

Input:

Ten cards separated by spaces from stdin or as command line arguments, whichever you prefer. The first five cards are Player 1's hand while the last five are Player 2's hand. Each card will be a two letter string of the form RS where R is rank and S is suit. The ranks range from 2-9, T for ten, and J, Q, K, and A for Jack, Queen, King, and Ace respectively. The suits are H, D, C, S for Hearts, Diamonds, Clubs, and Spades respectively. You must output the number of the player that wins: '1' or '2'.

Examples of Cards:

AS - the Ace of Spades
QD - the Queen of Diamonds
2C - the Two of Clubs
TH - the Ten of Hearts


Input to Output Examples:

5H 5C 6S 7S KD 2C 3S 8S 8D TD -&gt; 2


Explanation: Player 1 has a Pair of Fives while Player 2 has a Pair of Eights.

5D 8C 9S JS AC 2C 5C 7D 8S QH -&gt; 1


Explanation: Neither Player has anything special, but Player 1's high card is an Ace while Player 2's high card is a Queen.

2D 9C AS AH AC 3D 6D 7D TD QD -&gt; 2


Explanation: Player 1 has Three Aces, Player 2 has a Flush of Diamonds.

4D 6S 9H QH QC 3D 6D 7H QD QS -&gt; 1


Explanation: Both players have a Pair of Queens, but Player 1's second highest card is a Nine whereas Player 2's is a Seven.

Rules and Clarifications:


Refer to the standard ranking of poker hands for the details of comparing hands.
You may assume that there are no repeated cards in each pair of hands.
You may assume that there is a definite winner in each case.
Suit does not factor into the ranking of a hand. For example, two royal flushes of different suits are equal (therefore any input where both players have a royal flush is invalid by the preceding rule).
As this is code golf, the shortest answer wins.


Notes:


Related to this question and this one.
Based on Project Euler Problem 54
Python - 774 722 707 698 685 chars
import sys
t,q,e,u='--23456789TJQKA','SDCH',enumerate,len
_=lambda c,i=0:chr(97+c[i])
def j(s):
 v,g,l=[0]*15,[0]*4,''
 for c in s:
  r,s=c[0],c[1];v[t.find(r)]+=1;g[q.find(s)]+=1
 c,h,k,m,f=0,0,[0,0,[],[],[]],0,0
 for x,i in e(v):
  for b in[2,3,4]:
   if i==b:k[b]+=[x]
 v[1]=v[14]
 for x,i in e(v):
  if i:
   c+=1
   if c==5:m,h=1,x
   if i==1:l+=_([x])
  else:c=0
 f,l,d=max(g)//5*2,l[::-1],'';z=f+m
 if z==3:d='z'+l
 if k[4]:d='y'+_(k[4])+l
 if k[2] and k[3]:d='x'+_(k[3])+_(k[2])
 if z==2:d='w'+l
 if z==1:d='v'+_([h])
 if k[3]:d='u'+_(k[3])+l
 if u(k[2])&gt;1:d='t'+_(k[2],1)+_(k[2])+l
 if u(k[2])==1&gt;u(k[3]):d='s'+_(k[2])+l
 return d or l
p=sys.argv
print(1+(j(p[1:6])&lt;j(p[6:])))

I chose to generate a string for each hand that represents it, starting with a character for the type of hand, followed by characters describing the particular variation of the type (for example, which card did you just have 4 of?), followed by the values of the remaining cards in case of a tie (if both players have the same double pair, the 5th card will have to decide who wins). I've tested it quite extensively, but I don't actually play poker, so I hope I got it right. Also, I know it's not fully golfed yet, I can probably shave off a few dozen chars later on.