Day 01: hoo hoo hee hee I refactor da code
This commit is contained in:
parent
b1de3de1b9
commit
c8166089be
16
src/01.rkt
16
src/01.rkt
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue