From faff40a314d4efd64d49b3534e36e3ca758f30f1 Mon Sep 17 00:00:00 2001 From: Alfred Melch Date: Thu, 10 Dec 2020 20:19:58 +0100 Subject: [PATCH] Solve 2020/10 --- 2020/10/input | 99 ++++++++++++++++++++++++++++++++++++++++++++ 2020/10/solution1.py | 21 ++++++++++ 2020/10/solution2.py | 18 ++++++++ 3 files changed, 138 insertions(+) create mode 100644 2020/10/input create mode 100644 2020/10/solution1.py create mode 100644 2020/10/solution2.py diff --git a/2020/10/input b/2020/10/input new file mode 100644 index 0000000..265b6f8 --- /dev/null +++ b/2020/10/input @@ -0,0 +1,99 @@ +77 +58 +25 +92 +14 +154 +105 +112 +147 +63 +84 +109 +24 +129 +49 +102 +130 +128 +134 +88 +95 +70 +80 +4 +153 +17 +145 +122 +39 +117 +93 +65 +3 +2 +139 +101 +148 +37 +27 +1 +87 +64 +23 +59 +42 +146 +43 +151 +116 +46 +115 +118 +131 +94 +19 +33 +12 +107 +10 +7 +73 +78 +53 +11 +135 +79 +60 +32 +141 +31 +140 +98 +136 +72 +38 +152 +30 +74 +106 +50 +13 +26 +155 +67 +20 +66 +91 +56 +34 +125 +52 +51 +18 +108 +57 +81 +119 +71 +144 diff --git a/2020/10/solution1.py b/2020/10/solution1.py new file mode 100644 index 0000000..596be09 --- /dev/null +++ b/2020/10/solution1.py @@ -0,0 +1,21 @@ +with open('input', 'r') as f: + adapters = list(map(int, f.readlines())) + +adapters.sort() +print(adapters) + +num1 = 0 +num3 = 1 +prev = 0 + +for adapter in adapters: + if adapter - prev == 1: + num1 += 1 + if adapter - prev == 3: + num3 += 1 + prev = adapter + +print(f'Number of adapters: {len(adapters)}') +print(f'1-jolt: {num1}, 3-jolt: {num3}') +print('Solution:') +print(num1 * num3) diff --git a/2020/10/solution2.py b/2020/10/solution2.py new file mode 100644 index 0000000..f49da0e --- /dev/null +++ b/2020/10/solution2.py @@ -0,0 +1,18 @@ +from collections import defaultdict + +with open('input', 'r') as f: + adapters = list(map(int, f.readlines())) + +adapters.append(0) +adapters.sort() +adapters.append(adapters[-1] + 3) +print(adapters) + +countMap = defaultdict(int) +countMap[0] = 1 + +for adapter in adapters: + for target in range(1, 4): + countMap[adapter + target] += countMap[adapter] + +print(countMap[adapters[-1]])