Day 01: hoo hoo hee hee I refactor da code

This commit is contained in:
Jonathan Chan 2021-11-30 21:54:11 -08:00
parent 7933893dbb
commit ed2c912d10
1 changed files with 5 additions and 11 deletions

View File

@ -4,21 +4,15 @@
(define input (map string->number (problem-input 1))) (define input (map string->number (problem-input 1)))
(define (deltas depths) (define (deltas nth-rest)
(for/list ([depth-prev depths] (for/list ([depth-prev input]
[depth-next (rest depths)]) [depth-next (nth-rest input)])
(- depth-next depth-prev))) (- depth-next depth-prev)))
(define window-sums
(for/list ([depth-prev input]
[depth-curr (rest input)]
[depth-next (rest (rest input))])
(+ depth-prev depth-curr depth-next)))
(define part1 (define part1
(count positive? (deltas input))) (count positive? (deltas cdr)))
(define part2 (define part2
(count positive? (deltas window-sums))) (count positive? (deltas cdddr)))
(show-solution part1 part2) (show-solution part1 part2)