You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
aoc-racket/2017/d11/main.rkt

24 lines
763 B
Racket

7 years ago
#lang reader "../aoc-lang.rkt"
(provide (rename-out [#%mb #%module-begin]))
(define-macro (#%mb (STARS) (HEX ...) ...)
#'(#%module-begin
7 years ago
(time ((if (eq? 'STARS ') one-star two-star) (list HEX ...)) ...)))
7 years ago
(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)))))