aboutsummaryrefslogtreecommitdiff
path: root/aoc/2021/day01/part2.neb
diff options
context:
space:
mode:
authormryouse2023-06-03 20:22:18 +0000
committermryouse2023-06-03 20:22:18 +0000
commit7b7bf727da3250907284368b98b0083a4b4e2386 (patch)
tree34802caea5181dc0fb97992746ab99b080448418 /aoc/2021/day01/part2.neb
initial commit
Diffstat (limited to 'aoc/2021/day01/part2.neb')
-rw-r--r--aoc/2021/day01/part2.neb19
1 files changed, 19 insertions, 0 deletions
diff --git a/aoc/2021/day01/part2.neb b/aoc/2021/day01/part2.neb
new file mode 100644
index 0000000..31e3c99
--- /dev/null
+++ b/aoc/2021/day01/part2.neb
@@ -0,0 +1,19 @@
+; return 1 if next three greater than first three
+(func is-increasing (inp)
+ (if (< (apply + (most inp)) (apply + (rest inp)))
+ 1
+ 0))
+
+; this works, but i don't like redefining variables
+(func iter-list (inp)
+ (def acc 0)
+ (for-count (- (length inp) 3)
+ (redef acc (+ acc (is-increasing (slice inp _idx_ 4)))))
+ acc)
+
+(def lines
+ (map string->int
+ (map strip
+ (read-lines "input.txt"))))
+
+(print (->string (iter-list lines)))