aboutsummaryrefslogtreecommitdiff
path: root/2020
diff options
context:
space:
mode:
authorj-james2020-12-10 07:31:01 +0000
committerj-james2020-12-11 01:26:07 +0000
commit6a0047d7c26b3aa691929d48c5e3248ba52e0da5 (patch)
tree93da7fda2f923bba43eacb4a2488b38c35904956 /2020
parent3a5bc1757d077c75ecce78800372895d668f7d42 (diff)
Day Ten, Part I
Diffstat (limited to '2020')
-rw-r--r--2020/input/ten.txt100
-rw-r--r--2020/ten.nim21
2 files changed, 121 insertions, 0 deletions
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