From 6a0047d7c26b3aa691929d48c5e3248ba52e0da5 Mon Sep 17 00:00:00 2001 From: j-james Date: Wed, 9 Dec 2020 23:31:01 -0800 Subject: Day Ten, Part I --- 2020/input/ten.txt | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2020/ten.nim | 21 +++++++++++ 2 files changed, 121 insertions(+) create mode 100644 2020/input/ten.txt create mode 100644 2020/ten.nim (limited to '2020') diff --git a/2020/input/ten.txt b/2020/input/ten.txt new file mode 100644 index 0000000..20133c9 --- /dev/null +++ b/2020/input/ten.txt @@ -0,0 +1,100 @@ +46 +63 +21 +115 +125 +35 +89 +17 +116 +90 +51 +66 +111 +142 +148 +60 +2 +50 +82 +20 +47 +24 +80 +101 +103 +16 +34 +72 +145 +141 +124 +14 +123 +27 +62 +61 +95 +138 +29 +7 +149 +147 +104 +152 +22 +81 +11 +96 +97 +30 +41 +98 +59 +45 +88 +37 +10 +114 +110 +4 +56 +122 +139 +117 +108 +91 +36 +146 +131 +109 +31 +75 +70 +140 +38 +121 +3 +28 +118 +54 +107 +84 +15 +76 +71 +102 +130 +132 +87 +55 +129 +83 +23 +42 +69 +1 +77 +135 +128 +94 diff --git a/2020/ten.nim b/2020/ten.nim new file mode 100644 index 0000000..9b8db68 --- /dev/null +++ b/2020/ten.nim @@ -0,0 +1,21 @@ +# Day Ten: Adapter Array +import os, strutils, sequtils, algorithm, math + +let input: string = paramStr(1) +var adapters: seq[int] = map(split(strip(readFile(input)), '\n'), parseInt) +adapters.add(0) +adapters = sorted(adapters) +adapters.add(adapters[^1] + 3) + +var jolt, one, three: int = 0 +for adapter in adapters: + case adapter - jolt + of 1: + inc(one) + of 3: + inc(three) + else: + discard + jolt = adapter + +echo one * three -- cgit v1.2.3-70-g09d2