blob: 80a9fc8e24a6635899b60725697852607a708df1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)))
|