Alter 3 files

Update `benchmark.json`
Update `__init__.py`
Update `running-times.png`
This commit is contained in:
akp 2022-12-02 10:23:53 +00:00
parent b0234096f2
commit f96d105082
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
3 changed files with 21 additions and 20 deletions

View file

@ -3,12 +3,12 @@
"dir": "challenges/2022/02-rockPaperScissors",
"implementations": {
"Python": {
"part.1.avg": 0.005764134883880615,
"part.1.max": 0.013495206832885742,
"part.1.min": 0.0013463497161865234,
"part.2.avg": 0.0034727907180786134,
"part.2.max": 0.008818864822387695,
"part.2.min": 0.0007967948913574219
"part.1.avg": 0.004535415172576904,
"part.1.max": 0.013599634170532227,
"part.1.min": 0.0014605522155761719,
"part.2.avg": 0.002712693929672241,
"part.2.max": 0.009427785873413086,
"part.2.min": 0.0008611679077148438
}
},
"numRuns": 1000

View file

@ -22,6 +22,15 @@ SCORES = {
}
magic_beans = [SCISSORS, ROCK, PAPER, SCISSORS, ROCK]
outcome_offsets = {
WIN: 1,
LOSE: -1,
DRAW: 0,
}
def parse(instr: str) -> List[Match]:
return [x.split(" ") for x in instr.strip().splitlines()]
@ -41,12 +50,12 @@ class Challenge(BaseChallenge):
if m[0] == m[1]:
score += SCORES[DRAW]
elif (
(m[1] == ROCK and m[0] == SCISSORS)
or (m[1] == PAPER and m[0] == ROCK)
or (m[1] == SCISSORS and m[0] == PAPER)
):
score += SCORES[WIN]
else:
opponent = magic_beans.index(m[1], 1)
ours = magic_beans.index(m[0], opponent-1, opponent+2)
if opponent - ours == outcome_offsets[WIN]:
score += SCORES[WIN]
return score
@ -54,14 +63,6 @@ class Challenge(BaseChallenge):
def two(instr: str) -> int:
inp = parse(instr)
magic_beans = [SCISSORS, ROCK, PAPER, SCISSORS, ROCK]
outcome_offsets = {
WIN: 1,
LOSE: -1,
DRAW: 0,
}
score = 0
for m in inp:
score += SCORES[m[1]]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Before After
Before After