Skip to content

Instantly share code, notes, and snippets.

@gnyman
Created December 3, 2022 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnyman/1db047fb746cdf2e9fda372439f0bf77 to your computer and use it in GitHub Desktop.
Save gnyman/1db047fb746cdf2e9fda372439f0bf77 to your computer and use it in GitHub Desktop.
# Open the file and read the strategy guide
with open('strategy_guide.txt') as file:
strategy_guide = [line.strip() for line in file]
# Define the score for each shape
SHAPE_SCORES = {'A': 1, 'B': 2, 'C': 3}
# Define the score for each outcome
OUTCOME_SCORES = {'X': 0, 'Y': 3, 'Z': 6}
# Define a dictionary that maps the opponent's shape to the shape that we need to choose
# in order to achieve the desired outcome
SHAPE_MAP = {
'X': {'A': 'C', 'B': 'A', 'C': 'B'},
'Y': {'A': 'A', 'B': 'B', 'C': 'C'},
'Z': {'A': 'B', 'B': 'C', 'C': 'A'},
}
# Initialize the total score to 0
total_score = 0
# Loop through each pair of characters in the strategy guide
for guide in strategy_guide:
# Split the guide into two values
opponent_choice, our_choice = guide.split()
# Use the SHAPE_MAP to determine the shape that we should choose
our_shape = SHAPE_MAP[our_choice][opponent_choice]
# Calculate the score for the round
round_score = SHAPE_SCORES[our_shape] + OUTCOME_SCORES[our_choice]
# Add the score for the round to the total score
total_score += round_score
# Print the total score
print(total_score)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment