Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions project_euler/problem_54/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"""
from __future__ import annotations

import os


class PokerHand(object):
"""Create an object representing a Poker Hand based on an input of a
Expand Down Expand Up @@ -356,3 +358,24 @@ def __ge__(self, other):

def __hash__(self):
return object.__hash__(self)


def solution() -> int:
# Solution for problem number 54 from Project Euler
# Input from poker_hands.txt file
answer = 0
script_dir = os.path.abspath(os.path.dirname(__file__))
poker_hands = os.path.join(script_dir, "poker_hands.txt")
with open(poker_hands, "r") as file_hand:
for line in file_hand:
player_hand = line[:14].strip()
opponent_hand = line[15:].strip()
player, opponent = PokerHand(player_hand), PokerHand(opponent_hand)
output = player.compare_with(opponent)
if output == "Win":
answer += 1
return answer


if __name__ == "__main__":
solution()