diff options
Diffstat (limited to 'aoc/day01/part1.neb')
| -rw-r--r-- | aoc/day01/part1.neb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/aoc/day01/part1.neb b/aoc/day01/part1.neb new file mode 100644 index 0000000..80a9fc8 --- /dev/null +++ b/aoc/day01/part1.neb @@ -0,0 +1,43 @@ +; this feels more lisp-y +; maximum recursion depth reached quickly :( +(func increase-count-recur (inp acc) + (branch + ((eq? 0 (list-length (rest inp))) acc) + ((> (first (rest inp)) (first inp)) + (increase-count-recur (rest inp) (+ 1 acc))) + (#true + (increase-count-recur (rest inp) acc)))) + +; this works, but i don't like redefining variables +(func increase-count-iter (inp) + (def acc 0) + (def prev (first inp)) + (for-each (rest inp) + (if (> _item_ prev) + (redef acc (+ 1 acc))) + (redef prev _item_)) + acc) + +(func pairwise (inp) + (zip (list-reverse (rest (list-reverse inp))) (rest inp))) + +; what i really need to get working is 'apply +(func list-subtract (lst) + (- (first lst) (list-subtract (rest lst)))) + +(func increase-count-iter-2 (inp) + ;(print (->string (list-reverse (rest (list-reverse inp))))) + ;(print (->string (rest inp))) + (def pairwise (zip (list-reverse (rest (list-reverse inp))) (rest inp))) + (print (->string pairwise)) + ) + + +(def lines + (map string->int + (map strip + (read-lines "input.txt")))) + +;(print (->string (increase-count-recur lines 0))) +;(print (->string (increase-count-iter lines 0))) +(print (->string (increase-count-iter-2 lines 0))) |
