with open("day2/input.txt") as f:
input = f.read().splitlines()
pprint(input[:5])['B Y', 'A Z', 'C Z', 'A Y', 'A Y']
['B Y', 'A Z', 'C Z', 'A Y', 'A Y']
match_value (your_piece:str, opp_piece:str)
Returns the value of the match between your piece and the opponent’s piece - if equal, returns 3, else if you win then return 6 else return 0
| Type | Details | |
|---|---|---|
| your_piece | str | your piece (Rock/Paper/Scissors) |
| opp_piece | str | opponent’s piece (Rock/Paper/Scissors) |
| Returns | int |
print(match_value("Rock","Paper"))
print(match_value("Rock","Scissors"))
print(match_value("Paper","Paper"))
print(match_value("Paper","Scissors"))0
6
3
0
score (input:str)
Returns the score of each move by you and your opponent based on the combination of the match value plus the piece value.
Your opponent’s and your move (Rock,Paper,Scissors) which are encoded A,B,C and by X,Y,Z respectively.
| Type | Details | |
|---|---|---|
| input | str | a string containing your opponent’s and your move separated by a space |
| Returns | int |
find_strat_piece (opp_piece:str, your_strat:str)
Finds the piece that matches the strategy you picked given the opponent’s piece
| Type | Details | |
|---|---|---|
| opp_piece | str | your opponents piece (Rock, Paper,Scissors) |
| your_strat | str | your strategy (WIN,LOSE, DRAW) |
| Returns | str |
print(find_strat_piece("Rock","DRAW"))
print(find_strat_piece("Scissors","WIN"))
print(find_strat_piece("Paper","LOSE"))Rock
Rock
Rock
score_strat_action (input:str)
Returns the score given the opponents move and your strategy
| Type | Details | |
|---|---|---|
| input | str | a string containing your opponent’s move and your strategy separated by a space |
| Returns | int |
4
1
7