From a80f1ef819218c01a2d7083576cbd13c4a0171b4 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 15 Dec 2020 20:46:00 +0100 Subject: [PATCH] Huge cleanup --- 2020/15.py | 69 +++++------------------------------------------------- 1 file changed, 6 insertions(+), 63 deletions(-) diff --git a/2020/15.py b/2020/15.py index e88f3d2..13782a4 100755 --- a/2020/15.py +++ b/2020/15.py @@ -1,71 +1,17 @@ #!/usr/bin/env python from aoc import get_input # AoC -from collections import defaultdict +from collections import defaultdict as dd nums = list(map( int, get_input(15).split(","))) -firstNums = defaultdict(list) +firstNums = dd(list) -i = 0 -for n in nums: +for i, n in enumerate(nums): firstNums[n].append(i) - i += 1 - - -def addSeen(num): - firstNums.add(num) - -def copyNums(lst): - return [elem for elem in lst] - -def getFirstNum(num, start=len(firstNums)): - i = start - while i >= 0: - n = firstNums[i] - if( n[0] == num ): - return n[1] - i -= 1 - - -# def getNextNum(i): -# if( i >= len(nums) ): -# lastNum = nums[i-1] -# newNums = nums[:i-1] - -# if( lastNum == nums[i-2] ): -# nums.append(1) -# addSeen(1) - -# elif( not lastNum in firstNums ): # new number -# nums.append(0) -# addSeen( (lastNum, i-1) ) - -# elif( lastNum in firstNums ): # spoken before -# ei= getFirstNum(lastNum) -# fi = getFirstNum(lastNum, ei-1) -# newN = ei - fi # diff is still the same if ei = ei+1 -# nums.append(newN) -# addSeen( (newN, i-1) ) - - -# turn = 3 - -# while True: -# if( turn < 30000000 ): -# getNextNum(turn) -# print(turn, "/30000000") -# turn += 1 -# else: -# print(nums[-1]) -# break - - - def numbers(maxt): num = nums[-1] - prevnum = None for i in range(len(nums), maxt): numsSeen = len(firstNums[num]) @@ -74,17 +20,14 @@ def numbers(maxt): else: num = 0 - print(f"{num=} {i=} {nums=}") + #print(f"{num=} {i=} {nums=}") firstNums[num].append(i) return num - - -turn = 3 -#maxturn = 30000000 #maxturn = 2020 +#maxturn = 30000000 + maxturn = 10 -print("0, 3, 6, 0, 3, 3, 1, 0, 4, 0") print(numbers(maxturn))