65 lines
1.3 KiB
Python
65 lines
1.3 KiB
Python
from aoc.input import get_input
|
|
import copy
|
|
import itertools
|
|
import time
|
|
import collections
|
|
import re
|
|
from aoc.partselector import part_one, part_two
|
|
import functools
|
|
|
|
|
|
def pw(line):
|
|
return line.strip().split(",")
|
|
|
|
|
|
def p1():
|
|
inp = get_input(pw)
|
|
nmbrs = []
|
|
for sample in inp:
|
|
print(sample)
|
|
for i in inp:
|
|
nmbrs.append(int(i))
|
|
last = inp[-1]
|
|
for i in range(len(inp), 30000000):
|
|
if last not in nmbrs or len(list(filter(lambda x: x == last, nmbrs))) == 1:
|
|
number = 0
|
|
else:
|
|
pos = len(nmbrs) - nmbrs[-2::-1].index(last) - 2
|
|
opos = len(nmbrs) - 1
|
|
number = opos - pos
|
|
|
|
print(i + 1, ":", number, number - i)
|
|
nmbrs.append(number)
|
|
last = number
|
|
|
|
return inp
|
|
|
|
|
|
def p2():
|
|
inp = get_input(pw)
|
|
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)
|
|
|
|
|
|
result1 = None
|
|
if part_one():
|
|
start = time.time()
|
|
result1 = p1()
|
|
print(round(1000 * (time.time() - start), 2), "ms")
|
|
|
|
|
|
if part_two():
|
|
start = time.time()
|
|
p2()
|
|
print(round(1000 * (time.time() - start), 2), "ms")
|