63 lines
1.2 KiB
Python
63 lines
1.2 KiB
Python
"""
|
|
calculate the sum of all games for a coded game plan of rock-paper-scissors
|
|
-----
|
|
A : Rock -> 1
|
|
B : Paper -> 2
|
|
C : Scissors -> 3
|
|
x : Rock -> 1
|
|
Y : Paper -> 2
|
|
Z : Scissors -> 3
|
|
|
|
"""
|
|
|
|
shape_points = {
|
|
'X':1,
|
|
'Y':2,
|
|
'Z':3,
|
|
'A':1,
|
|
'B':2,
|
|
'C':3,
|
|
}
|
|
|
|
def game_points(them, you):
|
|
op,pl = shape_points[them],shape_points[you]
|
|
diff = pl - op + 1
|
|
# The +1 offsets the modulo so that a loss goes from -1 (2) to 0, a draw from 0 to 1 and a win from 1 to 2
|
|
return pl + (diff%3)*3
|
|
|
|
with open('2022/2/strategy_guide.txt') as filein:
|
|
games = [tuple(line.split()) for line in filein.readlines()]
|
|
|
|
score = sum([game_points(*game) for game in games])
|
|
|
|
print(score)
|
|
"""
|
|
new cypher:
|
|
x : lose
|
|
Y : draw
|
|
Z : win
|
|
"""
|
|
|
|
shape_points = {
|
|
'A':1,
|
|
'B':2,
|
|
'C':3,
|
|
'X':-1,
|
|
'Y':0,
|
|
'Z':1,
|
|
}
|
|
|
|
def game_points(them, goal):
|
|
op,goal = shape_points[them],shape_points[goal]
|
|
# get your optimal play
|
|
pl = (op + goal)%3
|
|
pl = 3 if pl==0 else pl
|
|
|
|
# see if you've won
|
|
diff = pl - op + 1
|
|
|
|
# The +1 offsets the modulo so that a loss goes from -1 (2) to 0, a draw from 0 to 1 and a win from 1 to 2
|
|
return pl + (diff%3)*3
|
|
|
|
print(sum([game_points(*game) for game in games]))
|
|
|