File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 42
42
"""
43
43
from __future__ import annotations
44
44
45
+ import os
46
+
45
47
46
48
class PokerHand (object ):
47
49
"""Create an object representing a Poker Hand based on an input of a
@@ -356,3 +358,24 @@ def __ge__(self, other):
356
358
357
359
def __hash__ (self ):
358
360
return object .__hash__ (self )
361
+
362
+
363
+ def solution () -> int :
364
+ # Solution for problem number 54 from Project Euler
365
+ # Input from poker_hands.txt file
366
+ answer = 0
367
+ script_dir = os .path .abspath (os .path .dirname (__file__ ))
368
+ poker_hands = os .path .join (script_dir , "poker_hands.txt" )
369
+ with open (poker_hands , "r" ) as file_hand :
370
+ for line in file_hand :
371
+ player_hand = line [:14 ].strip ()
372
+ opponent_hand = line [15 :].strip ()
373
+ player , opponent = PokerHand (player_hand ), PokerHand (opponent_hand )
374
+ output = player .compare_with (opponent )
375
+ if output == "Win" :
376
+ answer += 1
377
+ return answer
378
+
379
+
380
+ if __name__ == "__main__" :
381
+ solution ()
You can’t perform that action at this time.
0 commit comments