From 4c514babbe2abbe81c447acacd392d1b85f17d87 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 12 Dec 2016 07:40:17 -0800 Subject: [PATCH] start day12 --- 2016/day12/input.rkt | 24 ++++++++++++++++++++++++ 2016/day12/lang.rkt | 25 +++++++++++++++++++++++++ 2016/day12/test.rkt | 7 +++++++ 3 files changed, 56 insertions(+) create mode 100644 2016/day12/input.rkt create mode 100644 2016/day12/lang.rkt create mode 100644 2016/day12/test.rkt diff --git a/2016/day12/input.rkt b/2016/day12/input.rkt new file mode 100644 index 0000000..ed9d5e4 --- /dev/null +++ b/2016/day12/input.rkt @@ -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 \ No newline at end of file diff --git a/2016/day12/lang.rkt b/2016/day12/lang.rkt new file mode 100644 index 0000000..a00f7fd --- /dev/null +++ b/2016/day12/lang.rkt @@ -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) + \ No newline at end of file diff --git a/2016/day12/test.rkt b/2016/day12/test.rkt new file mode 100644 index 0000000..de3dce0 --- /dev/null +++ b/2016/day12/test.rkt @@ -0,0 +1,7 @@ +#lang reader "lang.rkt" +cpy 41 a +inc a +inc a +dec a +jnz a 2 +dec a \ No newline at end of file