Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

problem 54 _(:3)J)_

  • Loading branch information...
commit d78bf7a8f87d41b6157fef9e6e9ae6bf66200821 1 parent ad354f6
@tingleshao authored
Showing with 13 additions and 9 deletions.
  1. +13 −9 problem51to60/problem54.py
View
22 problem51to60/problem54.py
@@ -2,7 +2,7 @@
from sys import argv
SUIT = ['D','C','H','S']
-
+#SUIT = ['S','H','C','D']
def convert_to_digit(x):
if x.isdigit():
return int(x)
@@ -55,7 +55,7 @@ def does_player_one_win(p1, p2):
if is_full_house(p1, 1) != is_full_house(p2, 1):
return is_full_house(p1, 1) > is_full_house(p2, 1)
if is_full_house(p1, 2) != is_full_house(p2, 2):
- return is_full_house(p1, 2) > is_full_house(p2, 2)
+ return is_full_house(p1, 2) < is_full_house(p2, 2)
if is_straight(p1) != is_straight(p2):
return is_straight(p1) > is_straight(p2)
if is_three_of_a_kind(p1) != is_three_of_a_kind(p2):
@@ -81,12 +81,14 @@ def is_straight(p):
if convert_to_digit(p[i][0]) != convert_to_digit(p[i+1][0]) - 1:
return -1
return convert_to_digit(p[4][0])
+ return -1
def is_flush(p):
for i in range(4):
if p[i][1] != p[i+1][1]:
return -1
return convert_to_digit(p[4][0])
+ return -1
def is_straight_flush(p):
if (is_flush(p) > 0 and is_straight(p) > 0):
@@ -106,13 +108,13 @@ def is_four_of_a_kind(p):
return -1
def is_full_house(p, set):
- if set == 1 and convert_to_digit(p[0][0]) == convert_to_digit(p[1][0]) == convert_to_digit(p[2][0]) and convert_to_digit(p[3][0]) == convert_to_digit(p[4][0]):
+ if set == 1 and (convert_to_digit(p[0][0]) == convert_to_digit(p[1][0]) == convert_to_digit(p[2][0])) and (convert_to_digit(p[3][0]) == convert_to_digit(p[4][0])):
return convert_to_digit(p[0][0])
- if set == 2 and convert_to_digit(p[0][0]) == convert_to_digit(p[1][0]) == convert_to_digit(p[2][0]) and convert_to_digit(p[3][0]) == convert_to_digit(p[4][0]):
+ if set == 2 and (convert_to_digit(p[0][0]) == convert_to_digit(p[1][0]) == convert_to_digit(p[2][0])) and (convert_to_digit(p[3][0]) == convert_to_digit(p[4][0])):
return convert_to_digit(p[4][0])
- if set == 1 and convert_to_digit(p[0][0]) == convert_to_digit(p[1][0]) and convert_to_digit(p[2][0]) == convert_to_digit(p[3][0]) == convert_to_digit(p[4][0]):
+ if set == 1 and (convert_to_digit(p[0][0]) == convert_to_digit(p[1][0])) and (convert_to_digit(p[2][0]) == convert_to_digit(p[3][0]) == convert_to_digit(p[4][0])):
return convert_to_digit(p[4][0])
- if set == 2 and convert_to_digit(p[0][0]) == convert_to_digit(p[1][0]) and convert_to_digit(p[2][0]) == convert_to_digit(p[3][0]) == convert_to_digit(p[4][0]):
+ if set == 2 and (convert_to_digit(p[0][0]) == convert_to_digit(p[1][0])) and (convert_to_digit(p[2][0]) == convert_to_digit(p[3][0]) == convert_to_digit(p[4][0])):
return convert_to_digit(p[0][0])
return -1
@@ -153,6 +155,7 @@ def is_one_pair(p):
def is_high_card(p, card):
return convert_to_digit(p[4-card][0])
+ #return -1
def get_card_val(x):
@@ -167,15 +170,16 @@ def compare_card(x,y):
one_play_str_lst = pokers.readline().strip().split(' ')
player_one = []
player_two = []
- for i in range(5):
- player_one.append(one_play_str_lst[i])
- player_two.append(one_play_str_lst[5+i])
+ for k in range(5):
+ player_one.append(one_play_str_lst[k])
+ player_two.append(one_play_str_lst[5+k])
player_one.sort(compare_card)
player_two.sort(compare_card)
plays.append([player_one,player_two])
count = 0
for line in plays:
+ #print line
if does_player_one_win(line[0],line[1]):
count += 1
print count
Please sign in to comment.
Something went wrong with that request. Please try again.