Skip to content

Instantly share code, notes, and snippets.

@gnyman

gnyman/try2.py Secret

Created December 3, 2022 18:18
Show Gist options
  • Save gnyman/3c19a3b32ab2051969a05a47186cdb39 to your computer and use it in GitHub Desktop.
Save gnyman/3c19a3b32ab2051969a05a47186cdb39 to your computer and use it in GitHub Desktop.
def score_for_shape(shape):
if shape == 'X':
return 1
if shape == 'Y':
return 2
if shape == 'Z':
return 3
def score_for_outcome(outcome):
if outcome == 'win':
return 6
if outcome == 'draw':
return 3
if outcome == 'loss':
return 0
def score_for_round(opponent_shape, player_shape):
if opponent_shape == 'A' and player_shape == 'Z':
outcome = 'loss'
elif opponent_shape == 'B' and player_shape == 'X':
outcome = 'loss'
elif opponent_shape == 'C' and player_shape == 'Y':
outcome = 'loss'
elif opponent_shape == player_shape:
outcome = 'draw'
else:
outcome = 'win'
return score_for_shape(player_shape) + score_for_outcome(outcome)
def calculate_total_score(strategy_guide):
total_score = 0
for round in strategy_guide:
x = score_for_round(round[0], round[1])
total_score += x
return total_score
strategy_guide = [('A', 'Y'), ('B', 'X'), ('C', 'Z')]
print(calculate_total_score(strategy_guide))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment