From bb8f6e1e8aef38e20cd892c10325b3a161f8dd95 Mon Sep 17 00:00:00 2001 From: Jonas Neugebauer Date: Thu, 17 Dec 2020 20:52:27 +0100 Subject: [PATCH] Day 10 template --- 2020/day10_1.py | 37 +++++++++++++++++ 2020/day10_input.txt | 96 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 2020/day10_1.py create mode 100644 2020/day10_input.txt diff --git a/2020/day10_1.py b/2020/day10_1.py new file mode 100644 index 0000000..8655bfa --- /dev/null +++ b/2020/day10_1.py @@ -0,0 +1,37 @@ +from pprint import pprint + +input = [] +with open('day9_input.txt', 'r') as f: + for line in f.readlines(): + input.append(int(line.strip())) + + +# prepare prefix cache +prefix = 25 +cache = [] +for i in range(prefix-1): + cache.append([]) + for j in range(prefix-i-1): + cache[i].append(input[i]+input[i+j+1]) + +def check_val(cache, val): + for c in cache: + if val in c: + return True + return False + +# start checking +err = None +for i in range(len(input)-prefix): + val = input[i+prefix] + if check_val(cache, val): + cache = cache[1:] + for j in range(prefix-2): + cache[j].append(input[i+j+1]+val) + cache.append([input[i+prefix-1]+val]) + else: + err = i+prefix + break +print(err) +print(input[err-25:err]) +print(input[err]) \ No newline at end of file diff --git a/2020/day10_input.txt b/2020/day10_input.txt new file mode 100644 index 0000000..90bde44 --- /dev/null +++ b/2020/day10_input.txt @@ -0,0 +1,96 @@ +70 +102 +148 +9 +99 +63 +40 +52 +91 +39 +55 +28 +54 +22 +95 +61 +118 +35 +14 +21 +129 +82 +137 +45 +7 +87 +81 +25 +3 +108 +41 +11 +145 +18 +65 +80 +115 +29 +136 +42 +97 +104 +117 +141 +62 +121 +23 +96 +24 +128 +48 +1 +112 +8 +34 +144 +134 +116 +58 +147 +51 +84 +17 +126 +64 +68 +135 +10 +77 +105 +127 +73 +111 +90 +16 +103 +109 +98 +146 +123 +130 +69 +133 +110 +30 +122 +15 +74 +33 +38 +83 +92 +2 +53 +140 +4