|
|
@ -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)
|
|
|
@ -23,13 +23,13 @@ followed by a dash, a sector ID, and a checksum in square brackets.
|
|
|
|
(display "part a: ")
|
|
|
|
(display "part a: ")
|
|
|
|
(displayln (for/sum ([room (in-list rooms)]
|
|
|
|
(displayln (for/sum ([room (in-list rooms)]
|
|
|
|
#:when (real-room? room))
|
|
|
|
#:when (real-room? room))
|
|
|
|
($room-sector room)))
|
|
|
|
($room-sector room)))
|
|
|
|
(display "part b: ")
|
|
|
|
(display "part b: ")
|
|
|
|
(displayln
|
|
|
|
(displayln
|
|
|
|
(for/first ([room (in-list rooms)]
|
|
|
|
(for/first ([room (in-list rooms)]
|
|
|
|
#:when (equal? (shift-string ($room-name room) ($room-sector room))
|
|
|
|
#:when (equal? (shift-string ($room-name room) ($room-sector room))
|
|
|
|
"northpole object storage"))
|
|
|
|
"northpole object storage"))
|
|
|
|
($room-sector room)))))
|
|
|
|
($room-sector room)))))
|
|
|
|
(provide (rename-out [mb #%module-begin]))
|
|
|
|
(provide (rename-out [mb #%module-begin]))
|
|
|
|
|
|
|
|
|
|
|
|
#|
|
|
|
|
#|
|
|
|
@ -48,8 +48,8 @@ with ties broken by alphabetization.
|
|
|
|
(define (shift-string str shift)
|
|
|
|
(define (shift-string str shift)
|
|
|
|
(list->string
|
|
|
|
(list->string
|
|
|
|
(for/list ([c (in-string str)])
|
|
|
|
(for/list ([c (in-string str)])
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
[(char=? c #\-) #\space]
|
|
|
|
[(char=? c #\-) #\space]
|
|
|
|
[else
|
|
|
|
[else
|
|
|
|
(define a-val (char->integer #\a))
|
|
|
|
(define a-val (char->integer #\a))
|
|
|
|
(integer->char (+ (modulo (+ (char->integer c) (- a-val) shift) 26) a-val))]))))
|
|
|
|
(integer->char (+ (modulo (+ (char->integer c) (- a-val) shift) 26) a-val))]))))
|