You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
|
|
|
#lang reader "../aoc-lang.rkt"
|
|
|
|
(provide (rename-out [#%mb #%module-begin]) ★ ★★)
|
|
|
|
|
|
|
|
(define-macro (#%mb (STARS) TOKS ...)
|
|
|
|
#`(#%module-begin
|
|
|
|
(time (STARS (vector (λ () TOKS) ...)))))
|
|
|
|
|
|
|
|
(define regs (make-hasheq))
|
|
|
|
|
|
|
|
(provide set mul sub jnz)
|
|
|
|
(define-macro (value VAL) #'(let ([val 'VAL]) (if (number? val) val (hash-ref! regs val 0))))
|
|
|
|
(define-macro (set REG VAL) #'(hash-set! regs 'REG (value VAL)))
|
|
|
|
(define-macro (sub REG VAL) #'(hash-update! regs 'REG (λ (val) (- val (value VAL))) 0))
|
|
|
|
(define-macro (mul REG VAL) #'(begin (hash-update! regs 'mul-count add1 0)
|
|
|
|
(hash-update! regs 'REG (λ (val) (* val (value VAL))) 0)))
|
|
|
|
(define-macro (jnz REG VAL) #'(when (not (zero? (value REG))) (raise (value VAL))))
|
|
|
|
|
|
|
|
(define (★ insts [final-key 'mul-count])
|
|
|
|
(for/fold ([offset 0]
|
|
|
|
#:result (hash-ref regs final-key))
|
|
|
|
([i (in-naturals)]
|
|
|
|
#:break (not (<= 0 offset (sub1 (vector-length insts)))))
|
|
|
|
(with-handlers ([integer? (λ (num) (+ num offset))])
|
|
|
|
(define inst (vector-ref insts offset))
|
|
|
|
(inst)
|
|
|
|
(add1 offset))))
|
|
|
|
|
|
|
|
(define (★★ insts)
|
|
|
|
(hash-set! regs 'a 1)
|
|
|
|
(★ insts 'h))
|