Poker

Create a program that reads hand data for poker and outputs the corresponding hand ranking for each hand. The rules for this problem are as follows:

- Poker is a game played with 5 cards.
- There are no more than 5 cards of the same number.
- There are no jokers.
- Consider only the following poker hands (higher numbers indicate higher ranks):
  1. No hand (none of the below)
  2. One pair (2 cards of the same number)
  3. Two pair (2 sets of 2 cards of the same number)
  4. Three of a kind (3 cards of the same number)
  5. Straight (5 cards with consecutive numbers)
  6. Full house (3 cards of the same number and 2 cards of another same number)
  7. Four of a kind (4 cards of the same number)

Input:
Multiple datasets, each in the format: card1,card2,card3,card4,card5
Cards are represented as J for Jack (11), Q for Queen (12), K for King (13), A for Ace (1), and other numbers as their respective values.

Output:
For each dataset, output the highest possible hand that can be formed from the given hand. Follow the output example for hand representation.

Sample Input:
(As provided)

Output for the Sample Input:
(As provided)

Note: For the hand 3 3 2 3 3, the correct hand is "four card" instead of "two pair".

# Buggy version:
import sys

def is_onepair(x):
    for i in range(4):
        if x.count(x[i]) == 2:
            return True

    return False

def is_twopair(x):
    count = 0
    for e in x:
        for e2 in x:
            if e == e2:
                count += 1
            if count == 2:
                return True

    return False

def is_threecard(x):
    for i in range(3):
        if x.count(x[i]) == 3:
            return True

    return False

def is_straight(x):
    x.sort()
    if x[0] == 1 and x[1:] == [10, 11, 12, 13]:
        return True
    for i in range(4):
        if x[i]+1 != x[i+1]:
            return False
    
    return True

def is_fullhouse(x):
    if is_threecard(x) and is_onepair(x):
        return True

    return False
    
def is_fourcard(x):
    for i in range(2):
        if x.count(x[i]) == 4:
            return True

    return False

for line in sys.stdin.readlines():
    hand = list(map(int, line.split(',')))
    if is_fourcard(hand):
        print("four card")
    elif is_fullhouse(hand):
        print("full house")
    elif is_straight(hand):
        print("straight")
    elif is_threecard(hand):
        print("three card")
    elif is_twopair(hand):
        print("two pair")
    elif is_onepair(hand):
        print("one pair")
    else:
        print("null")

# Fixed version:
import sys

def is_onepair(x):
    for i in range(4):
        if x.count(x[i]) == 2:
            return True

    return False

def is_twopair(x):
    count = 0
    i = 0
    x.sort()
    while i < 5:
        if x.count(x[i]) == 2:
            i += 2
            count += 1
        else:
            i += 1
        if count == 2:
            return True

    return False

def is_threecard(x):
    for i in range(3):
        if x.count(x[i]) == 3:
            return True

    return False

def is_straight(x):
    x.sort()
    if x[0] == 1 and x[1:] == [10, 11, 12, 13]:
        return True
    for i in range(4):
        if x[i]+1 != x[i+1]:
            return False
    
    return True

def is_fullhouse(x):
    if is_threecard(x) and is_onepair(x):
        return True

    return False
    
def is_fourcard(x):
    for i in range(2):
        if x.count(x[i]) == 4:
            return True

    return False

for line in sys.stdin.readlines():
    hand = list(map(int, line.split(',')))
    if is_fourcard(hand):
        print("four card")
    elif is_fullhouse(hand):
        print("full house")
    elif is_straight(hand):
        print("straight")
    elif is_threecard(hand):
        print("three card")
    elif is_twopair(hand):
        print("two pair")
    elif is_onepair(hand):
        print("one pair")
    else:
        print("null")

# Buggy version:
def function(a,b,c,d,e):
	A=[a,b,c,d,e]
	A.sort()
	print(A)
	#4card
	if A[0]==A[3] or A[1]==A[4]:
		print("four card")
	#Full house
	elif (A[0]==A[1] and A[2]==A[4]) or (A[0]==A[2] and A[3]==A[4]):
		print("full house")
	#three card
	elif A[0]==A[2] or A[1]==A[3] or A[2]==A[4]:
		print("three card")
	elif (A[0]==A[1] and A[2]==A[3]) or (A[0]==A[1] and A[3]==A[4]) or (A[1]==A[2] and A[3]==A[4]):
		print("two pair")
	elif A[0]==A[1] or A[1]==A[2] or A[2]==A[3] or A[3]==A[4]:
		print("one pair")
	#straight A?????????
	elif A==[1,10,11,12,13]:
		print("straight")
	#straight A???????????????
	elif A[0]==A[1]-1==A[2]-2==A[3]-3==A[4]-4:
		print("straight")
	else:
		print("null")

while True:
	try:
		a,b,c,d,e=map(int,input().split(','))
		function(a,b,c,d,e)
	except EOFError:
		break

# Fixed version:
def function(a,b,c,d,e):
	A=[a,b,c,d,e]
	A.sort()
	if A[0]==A[3] or A[1]==A[4]:
		print("four card")
	elif (A[0]==A[1] and A[2]==A[4]) or (A[0]==A[2] and A[3]==A[4]):
		print("full house")
	elif A[0]==A[2] or A[1]==A[3] or A[2]==A[4]:
		print("three card")

	elif (A[0]==A[1] and A[2]==A[3]) or (A[0]==A[1] and A[3]==A[4]) or (A[1]==A[2] and A[3]==A[4]):
		print("two pair")
	elif A[0]==A[1] or A[1]==A[2] or A[2]==A[3] or A[3]==A[4]:
		print("one pair")
	elif A==[1,10,11,12,13]:
		print("straight")
	elif A[0]==A[1]-1==A[2]-2==A[3]-3==A[4]-4:
		print("straight")
	else:
		print("null")

while True:
	try:
		a,b,c,d,e=map(int,input().split(','))
		function(a,b,c,d,e)
	except EOFError:
		break

# Buggy version:
import sys
for e in sys.stdin:
 c=[list(map(int,e.split(','))).count(i+1)for i in range(13)];d=c+c
 print('four card'if 4 in c else'full house'if 2 in c else'three card'if 3 in c else'two pair'if c.count(2)-1 else'one pair'if 2 in c else'straight'if sum([1]*5==d[i:i+5]for i in range(10)) else'null')


# Fixed version:
import sys
for e in sys.stdin:
 e=list(map(int,e.split(',')))
 c=[e.count(i+1)for i in range(13)];d=c+c
 if 4 in c:s='four card'
 elif 3 in c:
  if 2 in c:s='full house'
  else:s='three card'
 elif 2 in c:
  if c.count(2)-1:s='two pair'
  else:s='one pair'
 elif sum([1]*5==d[i:i+5]for i in range(10)):s='straight'
 else:s='null'
 print(s)

# Buggy version:
import sys
for e in sys.stdin:
 e=sorted(map(int,e.split(',')))
 print([['null','straight'][e[4]-e[0]==4 or e[0]*10==e[1]],'one pair','two pair','three card','full house',0,'four card'][(sum(e.count(s)for s in e)//2-2])


# Fixed version:
import sys
for e in sys.stdin:
 e=sorted(map(int,e.split(',')))
 print([['null','straight'][e[0]*10==e[1]or e[4]-e[0]==4],'one pair','two pair','three card','full house',0,'four card'][sum(e.count(s)for s in e)//2-2])

# Buggy version:
from collections import Counter
import sys

for t in sys.stdin:
    l=sorted(map(int,t[:-1].split(",")))
    s=False
    p1=Counter(l)
    p2=Counter(p1.values())

    if 3 in p2 and 2 in p2:
        print("full house")
    elif 2 in p2:
        if p2[2]==1:
            print("one pair")
        elif p2[2]==2:
            print("two pair")
    elif 3 in p2:
        print("three card")
    elif 4 in p2:
        print("four card")
    else:
        for i in range(1,10):
            if list(range(i,i+5))==l:
                print("straight")
                s=True
                break
        if [1,10,11,12,13]==i:
            print("straight")
            s=True
        if not s:
            print("null")



# Fixed version:
from collections import Counter
import sys

for t in sys.stdin:
    l=sorted(map(int,t[:-1].split(",")))
    s=False
    p1=Counter(l)
    p2=Counter(p1.values())

    if 3 in p2 and 2 in p2:
        print("full house")
    elif 2 in p2:
        if p2[2]==1:
            print("one pair")
        elif p2[2]==2:
            print("two pair")
    elif 3 in p2:
        print("three card")
    elif 4 in p2:
        print("four card")
    else:
        for i in range(1,10):
            if list(range(i,i+5))==l:
                print("straight")
                s=True
                break
        if [1,10,11,12,13]==l:
            print("straight")
            s=True
        if not s:
            print("null")