master
Matthew Butterick 7 years ago
parent 42b6c84b74
commit b2b70dbc48

@ -0,0 +1,24 @@
#lang reader "../aoc-lang.rkt"
(provide (rename-out [#%mb #%module-begin]))
(define-macro (#%mb (STARS) (HEX ...) ...)
#'(#%module-begin
((if (eq? 'STARS ') one-star two-star) (list HEX ...)) ...))
(define origin '(0 0 0))
(define ne '(1 0 -1)) (define sw '(-1 0 1))
(define n '(0 1 -1)) (define s '(0 -1 1))
(define nw '(-1 1 0)) (define se '(1 -1 0))
(provide ne sw n s nw se)
(define (dist h1 h2) (/ (apply + (map abs (map - h1 h2))) 2))
(define (one-star hexes) (dist origin (apply map + hexes)))
(define (two-star hexes)
(for/fold ([sum origin]
[max-dist 0]
#:result max-dist)
([h (in-list hexes)])
(define this-sum (map + h sum))
(values this-sum (max max-dist (dist origin this-sum)))))

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,5 @@
#lang reader "main.rkt"
ne,ne,ne ; is 3 steps away.
ne,ne,sw,sw ; is 0 steps away (back where you started).
ne,ne,s,s ; is 2 steps away (se,se).
se,sw,se,sw,sw ; is 3 steps away (s,s,sw).

@ -0,0 +1,5 @@
#lang reader "main.rkt" ★★
ne,ne,ne ; is 3 steps away.
ne,ne,sw,sw ; is 0 steps away (back where you started).
ne,ne,s,s ; is 2 steps away (se,se).
se,sw,se,sw,sw ; is 3 steps away (s,s,sw).