diff options
Diffstat (limited to '2020/ten.nim')
-rw-r--r-- | 2020/ten.nim | 12 |
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 |