From 54998c7452e423a6aa7deef3047f0c334c3272f6 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Fri, 5 Mar 2021 12:31:00 -0700 Subject: Updating till day 10 --- day10/day10.py | 28 +++++++++++++++++ day10/input | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 day10/day10.py create mode 100644 day10/input (limited to 'day10') diff --git a/day10/day10.py b/day10/day10.py new file mode 100644 index 0000000..041c758 --- /dev/null +++ b/day10/day10.py @@ -0,0 +1,28 @@ +"""Day 10.""" +from collections import Counter +from itertools import combinations +from functools import lru_cache + +with open("input") as f: + orig_nums = sorted([int(x) for x in f.read().rstrip().split("\n")]) + +rated_for = orig_nums[-1] + 3 +nums = [0] + orig_nums + [rated_for] +diffs = [j - i for i, j in list(zip(nums[:-1], nums[1:]))] +counter = Counter(diffs) + +# Part 1 +print(counter[1] * counter[3]) + +@lru_cache(None) +def arrangements(jolts, prev) -> int: + first, rest = jolts[0], jolts[1:] + if first - prev > 3: + return 0 + elif not rest: + return 1 + else: + return (arrangements(rest, first) + # Use first + arrangements(rest, prev)) # Skip first + +print(arrangements(tuple(orig_nums), 0)) diff --git a/day10/input b/day10/input new file mode 100644 index 0000000..4a713ff --- /dev/null +++ b/day10/input @@ -0,0 +1,96 @@ +99 +3 +1 +11 +48 +113 +131 +43 +82 +19 +4 +153 +105 +52 +56 +109 +27 +119 +147 +31 +34 +13 +129 +17 +61 +10 +29 +24 +12 +104 +152 +103 +80 +116 +79 +73 +21 +133 +44 +18 +74 +112 +136 +30 +146 +100 +39 +130 +91 +124 +70 +115 +81 +28 +151 +2 +122 +87 +143 +62 +7 +126 +95 +75 +20 +123 +63 +125 +53 +45 +141 +14 +67 +69 +60 +114 +57 +142 +150 +42 +78 +132 +66 +88 +140 +139 +106 +38 +85 +37 +51 +94 +98 +86 +68 + -- cgit v1.2.3