1
0
Fork 0

Day 24: Minor adjustments for pretty

This commit is contained in:
Jonathan Chan 2020-12-23 22:53:53 -08:00 committed by Jonathan Chan
parent 6ef3f4d456
commit 6b7046e910
1 changed files with 17 additions and 14 deletions

View File

@ -8,17 +8,17 @@
(define input (map parse (problem-input 24))) (define input (map parse (problem-input 24)))
(define (walk path) (define (walk path)
(let loop ([coord (list 0 0)] (for/fold ([x 0]
[path path]) [y 0]
(if (empty? path) #:result (list x y))
coord ([dir path])
(match (list (first path) coord) (match dir
[`(e (,x ,y)) (loop (list (add1 x) y) (rest path))] ['e (values (add1 x) y)]
[`(w (,x ,y)) (loop (list (sub1 x) y) (rest path))] ['w (values (sub1 x) y)]
[`(se (,x ,y)) (loop (list x (add1 y)) (rest path))] ['se (values x (add1 y))]
[`(nw (,x ,y)) (loop (list x (sub1 y)) (rest path))] ['nw (values x (sub1 y))]
[`(ne (,x ,y)) (loop (list (add1 x) (sub1 y)) (rest path))] ['ne (values (add1 x) (sub1 y))]
[`(sw (,x ,y)) (loop (list (sub1 x) (add1 y)) (rest path))])))) ['sw (values (sub1 x) (add1 y))])))
(define (keep-flipped coords) (define (keep-flipped coords)
(for/fold ([keep (set)]) (for/fold ([keep (set)])
@ -29,9 +29,12 @@
(define (neighbours coord) (define (neighbours coord)
(match-let ([(list x y) coord]) (match-let ([(list x y) coord])
(list (list (add1 x) y) (list (sub1 x) y) `((,(add1 x) ,y)
(list x (add1 y)) (list x (sub1 y)) (,(sub1 x) ,y)
(list (add1 x) (sub1 y)) (list (sub1 x) (add1 y))))) (,x ,(add1 y))
(,x ,(sub1 y))
(,(add1 x) ,(sub1 y))
(,(sub1 x) ,(add1 y)))))
(define (flip coords) (define (flip coords)
(let* ([xs (set-map coords first)] [min-x (sub1 (apply min xs))] [max-x (add1 (apply max xs))] (let* ([xs (set-map coords first)] [min-x (sub1 (apply min xs))] [max-x (add1 (apply max xs))]