master
parent
8d68af640e
commit
8409ba623e
@ -0,0 +1,30 @@
|
||||
#lang reader "../aoc-lang.rkt"
|
||||
(provide (rename-out [#%mb #%module-begin]))
|
||||
|
||||
(define-macro (#%mb (STARS) (TOK ...) ...)
|
||||
#`(#%module-begin
|
||||
(inst TOK ...) ...
|
||||
(if (eq? 'STARS '★) (max-arg vals) max-seen)))
|
||||
|
||||
(define vals (make-hasheq))
|
||||
(define (get-val key) (hash-ref! vals key 0))
|
||||
(define (max-arg vals) (argmax cdr (hash->list vals)))
|
||||
(define max-seen 0)
|
||||
(define (set-val! key updater)
|
||||
(hash-update! vals key updater 0)
|
||||
(set! max-seen (max max-seen (cdr (max-arg vals)))))
|
||||
|
||||
(provide >= <= < > ==)
|
||||
(define-macro-cases cmp
|
||||
[(_ ==) #'=]
|
||||
[(_ !=) #'(negate =)]
|
||||
[(_ OTHER) #'OTHER])
|
||||
|
||||
(define-macro-cases updater
|
||||
[(_ dec) #'-]
|
||||
[(_ inc) #'+])
|
||||
|
||||
(provide if)
|
||||
(define-macro (inst TARGET UPDATE-OP UPDATE-VAL if SRC CMP VAL)
|
||||
#'(when ((cmp CMP) (get-val 'SRC) VAL)
|
||||
(set-val! 'TARGET (λ (val) ((updater UPDATE-OP) val UPDATE-VAL)))))
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,5 @@
|
||||
#lang reader "main.rkt" ★
|
||||
b inc 5 if a > 1
|
||||
a inc 1 if b < 5
|
||||
c dec -10 if a >= 1
|
||||
c inc -20 if c == 10
|
@ -0,0 +1,5 @@
|
||||
#lang reader "main.rkt" ★★
|
||||
b inc 5 if a > 1
|
||||
a inc 1 if b < 5
|
||||
c dec -10 if a >= 1
|
||||
c inc -20 if c == 10
|
Reference in New Issue