Compare commits
No commits in common. "787381537b0a06733900c97931e8f06fecaed99f" and "6f0ffd34dbf615a002bc52b5b49bdea378dc4dfd" have entirely different histories.
787381537b
...
6f0ffd34db
|
@ -1,61 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import enum
|
||||
import sys
|
||||
|
||||
|
||||
class Outcome(enum.IntEnum):
|
||||
Lose = 0
|
||||
Draw = 3
|
||||
Win = 6
|
||||
|
||||
|
||||
class Choice(enum.IntEnum):
|
||||
Rock = 1
|
||||
Paper = 2
|
||||
Scissors = 3
|
||||
|
||||
@classmethod
|
||||
def from_input(cls, input: str) -> "Choice":
|
||||
match input:
|
||||
case "A" | "X":
|
||||
return cls.Rock
|
||||
case "B" | "Y":
|
||||
return cls.Paper
|
||||
case "C" | "Z":
|
||||
return cls.Scissors
|
||||
assert False # Sanity check
|
||||
|
||||
|
||||
def score(other: Choice, you: Choice) -> int:
|
||||
def outcome() -> Outcome:
|
||||
if other == you:
|
||||
return Outcome.Draw
|
||||
if other == other.Rock and you == other.Paper:
|
||||
return Outcome.Win
|
||||
if other == other.Paper and you == other.Scissors:
|
||||
return Outcome.Win
|
||||
if other == other.Scissors and you == other.Rock:
|
||||
return Outcome.Win
|
||||
return Outcome.Lose
|
||||
|
||||
return you + outcome()
|
||||
|
||||
|
||||
Round = tuple[Choice, Choice]
|
||||
|
||||
|
||||
def solve(input: list[Round]) -> int:
|
||||
return sum(map(lambda round: score(*round), input))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input: list[Round] = [
|
||||
(Choice.from_input(round[0]), Choice.from_input(round[2]))
|
||||
for round in sys.stdin.readlines()
|
||||
]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2500
2022/d02/ex1/input
2500
2022/d02/ex1/input
File diff suppressed because it is too large
Load diff
|
@ -1,71 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import enum
|
||||
import sys
|
||||
|
||||
|
||||
class Outcome(enum.IntEnum):
|
||||
Lose = 0
|
||||
Draw = 3
|
||||
Win = 6
|
||||
|
||||
@classmethod
|
||||
def from_input(cls, input: str) -> "Outcome":
|
||||
match input:
|
||||
case "X":
|
||||
return cls.Lose
|
||||
case "Y":
|
||||
return cls.Draw
|
||||
case "Z":
|
||||
return cls.Win
|
||||
assert False # Sanity check
|
||||
|
||||
|
||||
class Choice(enum.IntEnum):
|
||||
Rock = 1
|
||||
Paper = 2
|
||||
Scissors = 3
|
||||
|
||||
@classmethod
|
||||
def from_input(cls, input: str) -> "Choice":
|
||||
match input:
|
||||
case "A":
|
||||
return cls.Rock
|
||||
case "B":
|
||||
return cls.Paper
|
||||
case "C":
|
||||
return cls.Scissors
|
||||
assert False # Sanity check
|
||||
|
||||
|
||||
def score(other: Choice, outcome: Outcome) -> int:
|
||||
def choice() -> Choice:
|
||||
match outcome:
|
||||
case Outcome.Lose:
|
||||
delta = -1
|
||||
case Outcome.Draw:
|
||||
delta = 0
|
||||
case Outcome.Win:
|
||||
delta = 1
|
||||
return Choice((other + delta - 1) % 3 + 1)
|
||||
|
||||
return outcome + choice()
|
||||
|
||||
|
||||
Round = tuple[Choice, Outcome]
|
||||
|
||||
|
||||
def solve(input: list[Round]) -> int:
|
||||
return sum(map(lambda round: score(*round), input))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input: list[Round] = [
|
||||
(Choice.from_input(round[0]), Outcome.from_input(round[2]))
|
||||
for round in sys.stdin.readlines()
|
||||
]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2500
2022/d02/ex2/input
2500
2022/d02/ex2/input
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue