start day12

2016
Matthew Butterick 8 years ago
parent 05f1f914db
commit 4c514babbe

@ -0,0 +1,24 @@
#lang reader "lang.rkt"
cpy 1 a
cpy 1 b
cpy 26 d
jnz c 2
jnz 1 5
cpy 7 c
inc d
dec c
jnz c -2
cpy a c
inc a
dec b
jnz b -2
cpy c b
dec d
jnz d -6
cpy 16 c
cpy 17 d
inc a
dec d
jnz d -2
dec c
jnz c -5

@ -0,0 +1,25 @@
#lang br/quicklang
;; http://adventofcode.com/2016/day/12
(provide read-syntax)
(define (read-syntax path port)
(strip-bindings
#`(module mod "lang.rkt"
#,@(for/list ([str (in-lines port)]
#:when (not (equal? str "")))
(format-datum `(handle ,@(map string->symbol (string-split str))))))))
(define (mb . INSTS)
#'(#%module-begin
(define insts (list . INSTS))
(define regs (make-hash '((a . 0)(b . 0)(c . 0)(d . 0))))
(let loop ([ptr 0])
(define inst (list-ref insts ptr))
(inst regs))))
(provide (rename-out [mb #%module-begin]))
(define-macro-cases handle
[(_ cpy X Y) #'(λ(regs) 42)])
(provide handle)

@ -0,0 +1,7 @@
#lang reader "lang.rkt"
cpy 41 a
inc a
inc a
dec a
jnz a 2
dec a