#advent of code 2024 #day 01 p1 & p2 #heapq was slower than manually sorting the lists import time t1 = time.time(); part1 = 0; part2 = 0; ListA = []; ListB = []; DictA = {}; f = open("01.in"); for l in f: n1,n2 = l.split(" "); ListA.append(int(n1)); ListB.append(int(n2)); DictA[int(n1)] = 0; f.close(); ListA = sorted(ListA); ListB = sorted(ListB); for i,x1 in enumerate(ListA): x2 = ListB[i]; d = abs(x1-x2); part1 += d; if x2 in DictA: DictA[x2] = DictA[x2] + 1; for x in DictA: part2 += x*DictA[x]; t2 = time.time(); print("part 1 = ", part1); print("part 2 = ", part2); print("time ", t2-t1);