Last active
December 15, 2020 08:27
-
-
Save kung-foo/c0889664bfaa2458a9ff96a5f6c60357 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
from collections import defaultdict | |
src = open("input.txt", "r").read() | |
# src = "0,3,6" | |
# src = "3,1,2" | |
src = [int(x) for x in src.split(",")] | |
t = len(src) | |
last = src[-1] | |
positions = defaultdict(list) | |
for i, v in enumerate(src): | |
positions[v].append(i) | |
def turn(): | |
global t, last | |
if len(positions[last]) == 1: | |
last = 0 | |
else: | |
pos = t - positions[last][-1] - 1 | |
pos2 = t - positions[last][-2] - 1 | |
last = pos2 - pos | |
positions[last].append(t) | |
t += 1 | |
while t < 30000000: | |
if t % 10000 == 0: | |
print(t) | |
turn() | |
print("answer", t, last) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment