day01,p1
parent
291de2e456
commit
bc5f33df4d
@ -0,0 +1,2 @@
|
||||
#lang aoc-racket/2016/day01
|
||||
R4, R5, L5, L5, L3, R2, R1, R1, L5, R5, R2, L1, L3, L4, R3, L1, L1, R2, R3, R3, R1, L3, L5, R3, R1, L1, R1, R2, L1, L4, L5, R4, R2, L192, R5, L2, R53, R1, L5, R73, R5, L5, R186, L3, L2, R1, R3, L3, L3, R1, L4, L2, R3, L5, R4, R3, R1, L1, R5, R2, R1, R1, R1, R3, R2, L1, R5, R1, L5, R2, L2, L4, R3, L1, R4, L5, R4, R3, L5, L3, R4, R2, L5, L5, R2, R3, R5, R4, R2, R1, L1, L5, L2, L3, L4, L5, L4, L5, L1, R3, R4, R5, R3, L5, L4, L3, L1, L4, R2, R5, R5, R4, L2, L4, R3, R1, L2, R5, L5, R1, R1, L1, L5, L5, L2, L1, R5, R2, L4, L1, R4, R3, L3, R1, R5, L1, L4, R2, L3, R5, R3, R1, L3
|
@ -0,0 +1,33 @@
|
||||
#lang br/quicklang
|
||||
(require racket/file)
|
||||
(module+ reader
|
||||
(provide read-syntax)
|
||||
(define (read-syntax path port)
|
||||
(strip-bindings
|
||||
#`(module day01-mod "day01.rkt"
|
||||
#,@(for/list ([t (in-list (string-split (port->string port) ", "))])
|
||||
`(turn ,@(string-split (string-trim t) #px"(?<=[LR])")))))))
|
||||
|
||||
(define-macro (mb . TURNS)
|
||||
#'(#%module-begin
|
||||
(solve . TURNS)))
|
||||
(provide (rename-out [mb #%module-begin]))
|
||||
|
||||
(define (solve . turns)
|
||||
(define loc
|
||||
(let loop ([loc 0]
|
||||
[dir 1]
|
||||
[turns turns])
|
||||
(if (empty? turns)
|
||||
loc
|
||||
(let* ([turn (car turns)]
|
||||
[rotation (car turn)]
|
||||
[dist (cdr turn)]
|
||||
[new-dir (* dir rotation)])
|
||||
(loop (+ loc (* new-dir dist)) new-dir (cdr turns))))))
|
||||
(+ (abs (imag-part loc)) (abs (real-part loc))))
|
||||
|
||||
(define-macro-cases turn
|
||||
[(turn "L" DIST) #'(cons +i (string->number DIST))]
|
||||
[(turn "R" DIST) #'(cons -i (string->number DIST))])
|
||||
(provide turn)
|
@ -1,6 +1,6 @@
|
||||
#lang info
|
||||
(define collection "aoc-racket")
|
||||
(define scribblings '(("aoc-racket.scrbl" (multi-page))))
|
||||
(define deps '("base" "scribble-lib" "sugar" "rackunit-lib" "math-lib"))
|
||||
(define deps '("base" "scribble-lib" "sugar" "rackunit-lib" "math-lib" "beautiful-racket-lib"))
|
||||
(define test-omit-paths (list #rx"rkt$"))
|
||||
(define build-deps '("rackunit-lib" "racket-doc" "scribble-doc" "rackunit-doc" "at-exp-lib" "math-doc"))
|
Reference in New Issue