From 2a23ef6d5db67fafea44ec8f1b1f3a264335687e Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Fri, 16 Apr 2021 12:28:08 -0600 Subject: day 15 part 2 --- day15/day15.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/day15/day15.py b/day15/day15.py index a5660a4..521d522 100644 --- a/day15/day15.py +++ b/day15/day15.py @@ -1,32 +1,30 @@ -"""Day 15.""" +"""Day 15. - -# reading off numbers -# starting numbers in input -# consider the most recently spoken number - -# new unique numbers mean the current says zero -# how far aprat the previous spoken one was +The 30000000 takes a while to complete +""" with open("input") as f: memory = list(map(int, f.read().rstrip().split(","))) -last_pos = {val: pos + 1 for pos, val in enumerate(memory)} +data = {val: {"position": pos + 1, "count": 1} for pos, val in enumerate(memory)} pos = len(memory) + 1 -for x in range(2020 - pos + 1): - last = memory[-1] - if memory.count(last) == 1: - memory.append(0) +last = memory[-1] + +# for x in range(2020 - pos + 1): +for x in range(30000000 - pos + 1): + if data[last]["count"] == 1: + val = 0 else: x = pos - 1 - y = last_pos[last] + y = data[last]["position"] val = x - y - memory.append(val) - last_pos[last] = x - if val not in last_pos: - last_pos[val] = pos + data[last]["position"] = x + if val not in data: + data[val] = {"position": pos, "count": 1} + last = val + data[val]["count"] += 1 pos += 1 -print(memory[-1]) +print(val) -- cgit v1.2.3