aboutsummaryrefslogtreecommitdiff
path: root/aoc
diff options
context:
space:
mode:
authormryouse2022-06-01 01:39:25 +0000
committermryouse2022-06-01 01:39:25 +0000
commitc1e97e348c5dbac6ddd085509582a01af2cb45bb (patch)
treecc0ac1ead0b7412f018128f5a0c1a29f10a8692a /aoc
parent2c89221c8bcced63406920c4420c0f3bf5aaa4d6 (diff)
day1 part2 (without slices)
Diffstat (limited to 'aoc')
-rw-r--r--aoc/day01/part2.neb26
1 files changed, 26 insertions, 0 deletions
diff --git a/aoc/day01/part2.neb b/aoc/day01/part2.neb
new file mode 100644
index 0000000..90a6358
--- /dev/null
+++ b/aoc/day01/part2.neb
@@ -0,0 +1,26 @@
+; add the first three items
+(func first-three (inp)
+ (apply + (list (first inp) (first (rest inp)) (first (rest (rest inp))))))
+
+; return 1 if next three greater than first three
+(func is-increasing (inp)
+ (if (< (first-three inp) (first-three (rest inp)))
+ 1
+ 0))
+
+; this works, but i don't like redefining variables
+; also this is slow, maybe there needs to be slices
+(func iter-list (inp)
+ (def acc 0)
+ (def prev inp)
+ (for-count (- (list-length inp) 3)
+ (redef acc (+ acc (is-increasing prev)))
+ (redef prev (rest prev)))
+ acc)
+
+(def lines
+ (map string->int
+ (map strip
+ (read-lines "input.txt"))))
+
+(print (->string (iter-list lines)))