@ -3,6 +3,10 @@ from typing import List, Tuple
class RPS :
WIN_SYM = " Z "
DRAW_SYM = " Y "
LOSS_SYM = " X "
ROCK = " R "
PAPER = " P "
SCISSOR = " S "
@ -47,6 +51,10 @@ class RockPaperScissorGuide:
The score for a single round is the score for the shape you selected ( 1 for Rock , 2 for Paper , and 3 for Scissors )
plus the score for the outcome of the round ( 0 if you lost , 3 if the round was a draw , and 6 if you won ) .
( Part 2 only )
The second column says how the round needs to end : X means you need to lose ,
Y means you need to end the round in a draw , and Z means you need to win .
"""
def __init__ ( self , path : str ) :
@ -55,7 +63,7 @@ class RockPaperScissorGuide:
self . file_path = path
def parse_file ( self ) - > List [ Tuple [ str , str ] ] :
def parse_file _v1 ( self ) - > List [ Tuple [ str , str ] ] :
strategy_guide = [ ]
with open ( self . file_path , " r " ) as file :
for line in file :
@ -64,3 +72,38 @@ class RockPaperScissorGuide:
strategy_guide . append ( ( RPS . RPS_SYM_TO_SHAPE [ a ] , RPS . RPS_SYM_TO_SHAPE [ b ] ) )
return strategy_guide
def parse_file ( self ) - > List [ Tuple [ str , str ] ] :
strategy_guide = [ ]
with open ( self . file_path , " r " ) as file :
for line in file :
line = line . replace ( " \n " , " " )
a , b = line . split ( " " )
a = RPS . RPS_SYM_TO_SHAPE [ a ]
answer = None
if b == RPS . WIN_SYM :
if a == RPS . ROCK :
answer = RPS . PAPER
elif a == RPS . PAPER :
answer = RPS . SCISSOR
elif a == RPS . SCISSOR :
answer = RPS . ROCK
elif b == RPS . DRAW_SYM :
answer = a
elif b == RPS . LOSS_SYM :
if a == RPS . ROCK :
answer = RPS . SCISSOR
elif a == RPS . PAPER :
answer = RPS . ROCK
elif a == RPS . SCISSOR :
answer = RPS . PAPER
if answer is None :
raise ValueError ( " Something went wrong with answer determination! " )
strategy_guide . append ( ( a , answer ) )
return strategy_guide