Skip to content

Instantly share code, notes, and snippets.

@gnyman

gnyman/try3.py Secret

Created December 3, 2022 18:19
Show Gist options
  • Save gnyman/76cc72703ab759aa7906ec79ba03293e to your computer and use it in GitHub Desktop.
Save gnyman/76cc72703ab759aa7906ec79ba03293e 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 == 'C':
outcome = 'loss'
elif opponent_shape == 'B' and player_shape == 'A':
outcome = 'loss'
elif opponent_shape == 'C' and player_shape == 'B':
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')]
def change_letters(strategy_guide):
new_strategy_guide = []
for round in strategy_guide:
opponent_shape = round[0]
player_shape = round[1]
if opponent_shape == 'A':
player_shape = 'X'
elif opponent_shape == 'B':
player_shape = 'Y'
elif opponent_shape == 'C':
player_shape = 'Z'
new_strategy_guide.append((opponent_shape, player_shape))
return new_strategy_guide
fixed_strategy_guide = change_letters(strategy_guide)
print(calculate_total_score(fixed_strategy_guide))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment