application/octet-stream
•
999 B
•
29 lines
#!/usr/bin/env nujel
; https://adventofcode.com/2021/day/1
[def example-list '[199 200 208 210 200 207 240 269 260 263]]
[defun count-increases [l]
"Compares every two items in L and increments a counter if the value increases"
[if [and l [cdr l]]
[+ [if [< [car l] [cadr l]] 1 0]
[count-increases [cdr l]]
0]]
]
[defun build-sums [l]
"Build sums out of 3 values with a sliding window"
[if [and l [cdr l] [cddr l]]
[cons [+ [car l] [cadr l] [caddr l]]
[build-sums [cdr l]]]
#nil]
]
[def result [count-increases example-list]]
[when [!= result 7] [throw [list :wrong-result "Wrong result" result]]]
[def result [count-increases [read [file/read "day1.input"]]]]
[when [!= result 1711] [throw [list :wrong-result "Wrong result" result]]]
[def result [count-increases [build-sums [read [file/read "day1.input"]]]]]
[when [!= result 1743] [throw [list :wrong-result "Wrong result" result]]]