From c2b5d89625d9820d5c648203ff8bbedc6e3e597c Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Thu, 10 Dec 2020 16:21:05 +0100 Subject: [PATCH] Day 10 (reduced memory usage) --- day10/part2.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/day10/part2.py b/day10/part2.py index ed990b2..fbd162a 100644 --- a/day10/part2.py +++ b/day10/part2.py @@ -1,16 +1,7 @@ -import numpy as np - lines = sorted(int(x.strip()) for x in open("input.txt")) -lines.append(lines[-1]+3) -lines.insert(0, 0) -lines = np.array(lines) - -diff = lines[1:] - lines[:-1] - one_count = 0 possibilities = 1 - one_cache = [1] @@ -22,12 +13,16 @@ def count_one_possibilities(one_cnt: int): # only 3 and 1 differences are available # 3 has to be taken / calculate possibilities for 1 hops -for num in diff: - if num == 1: +prev = 0 +for line in lines: + diff = line-prev + prev = line + if diff == 1: one_count += 1 - elif num == 3: + elif diff == 3: possibilities *= count_one_possibilities(one_count) one_count = 0 +possibilities *= count_one_possibilities(one_count) print(possibilities) # 64793042714624 print(one_cache) # {0: 1, 1: 1, 2: 2, 3: 4, 4: 7}