29 lines
523 B
Python
29 lines
523 B
Python
import copy
|
|
import itertools
|
|
import time
|
|
import collections
|
|
import re
|
|
import functools
|
|
|
|
|
|
|
|
def p2():
|
|
inp =[2,0,1,7,4,14,18]
|
|
nmbrs = {int(x): y + 1 for y, x in enumerate(inp[:-1])}
|
|
last = int(inp[-1])
|
|
|
|
for i in range(len(nmbrs) + 1, 30000000):
|
|
if last not in nmbrs:
|
|
nmbrs[last] = i
|
|
last = 0
|
|
else:
|
|
prev, nmbrs[last] = nmbrs[last], i
|
|
last = i - prev
|
|
|
|
print(last)
|
|
|
|
|
|
start = time.time()
|
|
p2()
|
|
print(round(1000 * (time.time() - start), 2), "ms")
|