Skip to content

Instantly share code, notes, and snippets.

@Mu-adventofcode
Last active July 2, 2022 16:40
Show Gist options
  • Save Mu-adventofcode/7fa40fefa80584fc7e6b75d46123e7cb to your computer and use it in GitHub Desktop.
Save Mu-adventofcode/7fa40fefa80584fc7e6b75d46123e7cb to your computer and use it in GitHub Desktop.
Advent of Code 2021 day 21 part 1
import re
def turns():
roll = 0
while True:
roll += 3
delta = (roll - 2) % 100 + (roll - 1) % 100 + roll % 100
yield delta, roll
inp = open("input_21.txt").read().strip()
pos = list(map(lambda x: int(x) - 1, re.findall(r": (\d+)", inp)))
score = [0, 0]
pid = 1 # player id
for delta, roll in turns():
pid = 1 - pid
pos[pid] = (pos[pid] + delta) % 10
score[pid] += pos[pid] + 1 # my pos is zero based
if score[pid] >= 1000:
print(score[1 - pid] * roll)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment