Skip to content

Instantly share code, notes, and snippets.

@gnyman
Created December 3, 2022 19:15
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/29c25e5bcdc50c287836f2108223904a to your computer and use it in GitHub Desktop.
Save gnyman/29c25e5bcdc50c287836f2108223904a 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 = {'R': 1, 'P': 2, 'S': 3}
# Define the score for each outcome
OUTCOME_SCORES = {'X': 0, 'Y': 3, 'Z': 6}
# 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()
# Get the first character of the opponent's choice as our shape
our_shape = opponent_choice[0]
# Calculate the outcome of the round
if (opponent_choice == 'R' and our_shape == 'S') or (opponent_choice == 'S' and our_shape == 'P') or (opponent_choice == 'P' and our_shape == 'R'):
# We lose the round
outcome = 'X'
elif (opponent_choice == 'R' and our_shape == 'P') or (opponent_choice == 'S' and our_shape == 'R') or (opponent_choice == 'P' and our_shape == 'S'):
# We win the round
outcome = 'Z'
else:
# The round is a draw
outcome = 'Y'
# 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