aboutsummaryrefslogtreecommitdiff
path: root/aoc/day01/part1.neb
diff options
context:
space:
mode:
authormryouse2022-05-23 04:00:01 +0000
committermryouse2022-05-23 04:00:01 +0000
commit5e788bc00a600b87a14e79c57a4d57bc9fb20fcb (patch)
tree4ca2e9da809d8b0bc2dd778f8c333983acb5cdf7 /aoc/day01/part1.neb
parentdd83eef30aa9d522a8ce694e34b542f3bcd954e4 (diff)
day 1 of AOC, not fully up to snuff
Diffstat (limited to 'aoc/day01/part1.neb')
-rw-r--r--aoc/day01/part1.neb43
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)))