; 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) ; (a b c d e) => ((a b) (b c) (c d) (d e)) (func pairwise (inp) (zip (list-reverse (rest (list-reverse inp))) (rest inp))) (func abs (num) (if (< num 0) (* (- 0 1) num) num)) (func list-subtract (lst) (def ret (apply - lst)) (- (/ (abs ret) ret) 1)) ; this algorithm is very roundabout (func increase-count-iter-2 (inp) (abs (/ (apply + (map list-subtract (pairwise inp))) 2))) (def lines (map string->int (map strip (read-lines "input.txt")))) ;(print (->string (increase-count-recur lines 0))) (print (->string (increase-count-iter lines))) (print (->string (increase-count-iter-2 lines)))