2016
Matthew Butterick 8 years ago
parent 3ba5818afd
commit 5924352c7a

@ -1,7 +1,6 @@
#lang br/quicklang #lang br/quicklang
(module+ reader
(provide read-syntax) (define (read-syntax path port)
(define (read-syntax path port)
(define turn-strings (string-split (port->string port) ",")) (define turn-strings (string-split (port->string port) ","))
(define turn-pattern #px"^([LR])(\\d+)$") (define turn-pattern #px"^([LR])(\\d+)$")
(define turn-datums (define turn-datums
@ -10,7 +9,8 @@
`(turn ,@(cdr (or match-result empty))))) `(turn ,@(cdr (or match-result empty)))))
(strip-bindings (strip-bindings
#`(module day01-mod "day01.rkt" #`(module day01-mod "day01.rkt"
#,@turn-datums)))) #,@turn-datums)))
(module+ reader (provide read-syntax))
(define-macro (mb . TURNS) (define-macro (mb . TURNS)
#'(#%module-begin #'(#%module-begin

@ -1,14 +1,14 @@
#lang br/quicklang #lang br/quicklang
(module+ reader
(provide read-syntax) (define (read-syntax path port)
(define (read-syntax path port)
(define moveset-strs (string-split (port->string port))) (define moveset-strs (string-split (port->string port)))
(define moveset-datums (define moveset-datums
(for*/list ([msstr (in-list moveset-strs)]) (for*/list ([msstr (in-list moveset-strs)])
`(moveset ,@(regexp-match* #rx"." msstr)))) `(moveset ,@(regexp-match* #rx"." msstr))))
(strip-bindings (strip-bindings
#`(module day01-mod "day02.rkt" #`(module day01-mod "day02.rkt"
#,@moveset-datums)))) #,@moveset-datums)))
(module+ reader (provide read-syntax))
(define-macro moveset #'list) (define-macro moveset #'list)
(provide moveset) (provide moveset)

@ -1,14 +1,14 @@
#lang br/quicklang #lang br/quicklang
(module+ reader
(provide read-syntax) (define (read-syntax path port)
(define (read-syntax path port)
(define moveset-strs (string-split (port->string port))) (define moveset-strs (string-split (port->string port)))
(define moveset-datums (define moveset-datums
(for*/list ([msstr (in-list moveset-strs)]) (for*/list ([msstr (in-list moveset-strs)])
`(moveset ,@(regexp-match* #rx"." msstr)))) `(moveset ,@(regexp-match* #rx"." msstr))))
(strip-bindings (strip-bindings
#`(module day01-mod "day02b.rkt" #`(module day01-mod "day02b.rkt"
#,@moveset-datums)))) #,@moveset-datums)))
(module+ reader (provide read-syntax))
(define-macro moveset #'list) (define-macro moveset #'list)
(provide moveset) (provide moveset)

@ -13,9 +13,7 @@
(provide (rename-out [mb #%module-begin])) (provide (rename-out [mb #%module-begin]))
(define-macro (triangle A B C) (define-macro (triangle A B C)
#'(list (string->number A) #'(map string->number (list A B C)))
(string->number B)
(string->number C)))
(provide triangle) (provide triangle)
(define (valid-triangle? triangle) (define (valid-triangle? triangle)

@ -1,9 +1,7 @@
#lang br/quicklang #lang br/quicklang
(require sugar/list) (require sugar/list)
(module+ reader (define (read-syntax path port)
(provide read-syntax)
(define (read-syntax path port)
(define triads (slice-at (map string-split (string-split (port->string port) "\n")) 3)) (define triads (slice-at (map string-split (string-split (port->string port) "\n")) 3))
(define new-triples (define new-triples
(slice-at (flatten (for/list ([triad (in-list triads)]) (slice-at (flatten (for/list ([triad (in-list triads)])
@ -11,7 +9,8 @@
(strip-bindings (strip-bindings
#`(module mod "day03b.rkt" #`(module mod "day03b.rkt"
#,@(for*/list ([triple (in-list new-triples)]) #,@(for*/list ([triple (in-list new-triples)])
`(triangle ,@triple)))))) `(triangle ,@triple)))))
(module+ reader (provide read-syntax))
(define-macro (mb . TRIANGLES) (define-macro (mb . TRIANGLES)
#'(#%module-begin #'(#%module-begin
@ -19,9 +18,7 @@
(provide (rename-out [mb #%module-begin])) (provide (rename-out [mb #%module-begin]))
(define-macro (triangle A B C) (define-macro (triangle A B C)
#'(list (string->number A) #'(map string->number (list A B C)))
(string->number B)
(string->number C)))
(provide triangle) (provide triangle)
(define (valid-triangle? triangle) (define (valid-triangle? triangle)

@ -1,12 +1,12 @@
#lang br/quicklang #lang br/quicklang
(module+ reader
(provide read-syntax) (define (read-syntax path port)
(define (read-syntax path port)
(strip-bindings (strip-bindings
#`(module mod "day04.rkt" #`(module mod "day04.rkt"
#,@(for*/list ([room-str (in-lines port)] #,@(for*/list ([room-str (in-lines port)]
#:when (not (equal? "" room-str))) #:when (not (equal? "" room-str)))
`(room ,@(cdr (regexp-match #px"^(.*)-(\\d+)\\[(\\w+)\\]$" room-str)))))))) `(room ,@(cdr (regexp-match #px"^(.*)-(\\d+)\\[(\\w+)\\]$" room-str)))))))
(module+ reader (provide read-syntax))
#| #|
Each room consists of an encrypted name (lowercase letters separated by dashes) Each room consists of an encrypted name (lowercase letters separated by dashes)