Skip to content

Instantly share code, notes, and snippets.

@ErikThorsell
Created December 9, 2018 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ErikThorsell/d60f73154c0b53944c4f46bc0c3932c3 to your computer and use it in GitHub Desktop.
Save ErikThorsell/d60f73154c0b53944c4f46bc0c3932c3 to your computer and use it in GitHub Desktop.
Day 9, AoC 2018
def task_1(players=9, last_marble_point=25):
scores = [0] * players
circle = [0]
p = 0
marble = 0
current_marble_idx = 0
while marble < last_marble_point:
p = (p + 1) % players
marble += 1
insert_at = (current_marble_idx + 2) % len(circle)
if marble % 23 == 0:
current_marble_idx = (insert_at - 9) % len(circle)
score = marble
score += circle.pop(current_marble_idx)
scores[p] += score
else:
circle.insert(insert_at, marble)
current_marble_idx = insert_at
return(max(scores))
def task_2(players=9, last_marble_point=25):
scores = [0] * players
circle = deque()
circle.insert(0, 0)
p = 0
marble = 0
while marble < last_marble_point:
p = (p + 1) % players
marble += 1
if marble % 23 == 0:
circle.rotate(-7)
score = marble
score += circle.pop()
scores[p] += score
else:
circle.rotate(2)
circle.append(marble)
return(max(scores))
## MAIN ##
if __name__ == "__main__":
data = get_input(9)
print(f"a: {task_1(data[0], data[1])}")
print(f"b: {task_2(data[0], data[1]*100)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment