From f74713233a3c9be2f4ea8a61be0000f06e8212a1 Mon Sep 17 00:00:00 2001 From: Thibaud Date: Thu, 10 Dec 2020 22:35:47 +0100 Subject: [PATCH] day 10 challenge --- day10/day10.py | 24 ++++++++++++ day10/input.txt | 99 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 day10/day10.py create mode 100644 day10/input.txt diff --git a/day10/day10.py b/day10/day10.py new file mode 100644 index 0000000..d667976 --- /dev/null +++ b/day10/day10.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +from collections import Counter + + +def part1(adapters): + counts = Counter() + # 1 for the socket, of 3 for the device + for current, next in zip([0] + adapters, adapters + [3]): + counts[next - current] += 1 + return counts[1] * counts[3] + + +def part2(adapters): + counts = Counter({0: 1}) + for jolt in adapters: + s = counts[jolt - 1] + counts[jolt - 2] + counts[jolt - 3] + counts[jolt] = s + return max(counts.values()) + + +if __name__ == "__main__": + adapters = sorted(int(l.rstrip()) for l in open("input.txt")) + print(part1(adapters)) + print(part2(adapters)) diff --git a/day10/input.txt b/day10/input.txt new file mode 100644 index 0000000..b8be7cc --- /dev/null +++ b/day10/input.txt @@ -0,0 +1,99 @@ +151 +94 +14 +118 +25 +143 +33 +23 +80 +95 +87 +44 +150 +39 +148 +51 +138 +121 +70 +69 +90 +155 +144 +40 +77 +8 +97 +45 +152 +58 +65 +63 +128 +101 +31 +112 +140 +86 +30 +55 +104 +135 +115 +16 +26 +60 +96 +85 +84 +48 +4 +131 +54 +52 +139 +76 +91 +46 +15 +17 +37 +156 +134 +98 +83 +111 +72 +34 +7 +108 +149 +116 +32 +110 +47 +157 +75 +13 +10 +145 +1 +127 +41 +53 +2 +3 +117 +71 +109 +105 +64 +27 +38 +59 +24 +20 +124 +9 +66