From 59d680584428b13dfcd333674312ee64c9b77afb Mon Sep 17 00:00:00 2001 From: j-james Date: Thu, 10 Dec 2020 17:26:33 -0800 Subject: Day Ten, Part II: 'Solve' recursively --- 2020/ten.nim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to '2020') 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 -- cgit v1.2.3-70-g09d2