From c8166089be8ea95d0951e43b3a597be14ca5daa2 Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Tue, 30 Nov 2021 21:54:11 -0800 Subject: [PATCH] Day 01: hoo hoo hee hee I refactor da code --- src/01.rkt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/01.rkt b/src/01.rkt index 78097dd..276c5c0 100644 --- a/src/01.rkt +++ b/src/01.rkt @@ -4,21 +4,15 @@ (define input (map string->number (problem-input 1))) -(define (deltas depths) - (for/list ([depth-prev depths] - [depth-next (rest depths)]) +(define (deltas nth-rest) + (for/list ([depth-prev input] + [depth-next (nth-rest input)]) (- 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 - (count positive? (deltas input))) + (count positive? (deltas cdr))) (define part2 - (count positive? (deltas window-sums))) + (count positive? (deltas cdddr))) (show-solution part1 part2)