/day2-part2-take2.py Secret
Created
December 3, 2022 19:13
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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} | |
print(OUTCOME_SCORES) | |
# Initialize the total score to 0 | |
total_score = 0 | |
# Loop through each pair of characters in the strategy guide | |
for guide in strategy_guide: | |
print(guide) | |
# Split the guide into two values | |
opponent_choice, our_choice = guide.split() | |
# Calculate the outcome of the round | |
if (opponent_choice == 'R' and our_choice == 'S') or (opponent_choice == 'S' and our_choice == 'P') or (opponent_choice == 'P' and our_choice == 'R'): | |
# We lose the round | |
outcome = 'X' | |
elif (opponent_choice == 'R' and our_choice == 'P') or (opponent_choice == 'S' and our_choice == 'R') or (opponent_choice == 'P' and our_choice == 'S'): | |
# We win the round | |
outcome = 'Z' | |
else: | |
# The round is a draw | |
outcome = 'Y' | |
# Calculate the score for the round | |
print(our_choice) | |
print(outcome) | |
round_score = SHAPE_SCORES[our_choice] + OUTCOME_SCORES[outcome] | |
# 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