diff options
| author | mryouse | 2022-05-24 01:40:05 +0000 |
|---|---|---|
| committer | mryouse | 2022-05-24 01:40:05 +0000 |
| commit | 75b2595299f0602142e5833b841702c8d0ac94af (patch) | |
| tree | f3de5fd6e9e61355241a85c1ce97260373a7e711 /aoc/day01 | |
| parent | 15a68c13e022db3bb200f94d4a051aecd6c1006f (diff) | |
add a roundabout functional solution
Diffstat (limited to 'aoc/day01')
| -rw-r--r-- | aoc/day01/part1.neb | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/aoc/day01/part1.neb b/aoc/day01/part1.neb index 80a9fc8..76f949c 100644 --- a/aoc/day01/part1.neb +++ b/aoc/day01/part1.neb @@ -18,20 +18,22 @@ (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))) -; what i really need to get working is 'apply +(func abs (num) + (if (< num 0) + (* (- 0 1) num) + num)) + (func list-subtract (lst) - (- (first lst) (list-subtract (rest lst)))) + (def ret (apply - lst)) + (- (/ (abs ret) ret) 1)) +; this algorithm is very roundabout (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)) - ) - + (abs (/ (apply + (map list-subtract (pairwise inp))) 2))) (def lines (map string->int @@ -39,5 +41,5 @@ (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))) +(print (->string (increase-count-iter lines))) +(print (->string (increase-count-iter-2 lines))) |
