diff options
| -rw-r--r-- | aoc/day01/part2.neb | 26 |
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))) |
