-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99689c1
commit a6c2031
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Any | ||
|
||
choice_map = {"A": 1, "B": 2, "C": 3, "X": 1, "Y": 2, "Z": 3} | ||
|
||
|
||
def puzzle(input: str) -> Any: | ||
lines = input.strip().split("\n") | ||
turns = [line.split() for line in lines] | ||
|
||
def score_for_round(opponent: str, us: str) -> int: | ||
score = 0 | ||
us_int = choice_map[us] | ||
opponent_int = choice_map[opponent] | ||
# always add our choice | ||
score += us_int | ||
# draw? | ||
if opponent_int == us_int: | ||
score += 3 | ||
# did we win? we always win if our choice is after theirs in order rock, paper, scissors | ||
elif 1 + (us_int - 2) % 3 == opponent_int: | ||
score += 6 | ||
return score | ||
|
||
total_score = 0 | ||
for turn in turns: | ||
total_score += score_for_round(turn[0], turn[1]) | ||
return total_score |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Any | ||
|
||
choice_map = {"A": 1, "B": 2, "C": 3, "X": 1, "Y": 2, "Z": 3} | ||
|
||
|
||
def puzzle(input: str) -> Any: | ||
lines = input.strip().split("\n") | ||
|
||
turns = [line.split() for line in lines] | ||
# rock, paper, scissors | ||
total_score = 0 | ||
for turn in turns: | ||
opponent = choice_map[turn[0]] | ||
us = choice_map[turn[1]] | ||
if us == 1: | ||
# we need to lose | ||
total_score += 1 + (opponent - 2) % 3 | ||
elif us == 2: | ||
# we need to draw - choose same as them | ||
total_score += 3 + opponent | ||
elif us == 3: | ||
# we need to win the round - choice choice to right- | ||
total_score += 6 + 1 + (opponent) % 3 | ||
return total_score |