aboutsummaryrefslogtreecommitdiff
path: root/2020
diff options
context:
space:
mode:
authorj-james2020-12-11 01:26:33 +0000
committerj-james2020-12-11 01:26:33 +0000
commit59d680584428b13dfcd333674312ee64c9b77afb (patch)
treead00d05d56dbaf2c2c29358f3f7b99eeb7df27c4 /2020
parent6a0047d7c26b3aa691929d48c5e3248ba52e0da5 (diff)
Day Ten, Part II: 'Solve' recursively
Diffstat (limited to '2020')
-rw-r--r--2020/ten.nim12
1 files changed, 12 insertions, 0 deletions
diff --git a/2020/ten.nim b/2020/ten.nim
index 9b8db68..3d96d0f 100644
--- a/2020/ten.nim
+++ b/2020/ten.nim
@@ -19,3 +19,15 @@ for adapter in adapters:
jolt = adapter
echo one * three
+
+var paths: int = 0
+proc recursive(adapters: seq[int]) =
+ for i in 0 .. (len(adapters) - 4):
+ if adapters[i+2] - adapters[i] <= 3:
+ recursive(adapters[i+2..^1])
+ if adapters[i+3] - adapters[i] <= 3:
+ recursive(adapters[i+3..^1])
+ inc(paths)
+
+recursive(adapters)
+echo paths