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.
20 lines
572 B
Racket
20 lines
572 B
Racket
7 years ago
|
#lang reader "../aoc-lang.rkt"
|
||
7 years ago
|
|
||
|
(provide (rename-out [#%mb #%module-begin]))
|
||
7 years ago
|
(define-macro (#%mb (STARS) (JMP) ...)
|
||
|
#`(#%module-begin
|
||
|
(escape (list->vector '(JMP ...)) 'STARS)))
|
||
7 years ago
|
|
||
7 years ago
|
(define (escape vec stars)
|
||
7 years ago
|
(let/ec exit
|
||
|
(for/fold ([pos 0])
|
||
|
([i (in-naturals)])
|
||
|
(unless (<= 0 pos (sub1 (vector-length vec)))
|
||
|
(exit i))
|
||
|
(define jmp (vector-ref vec pos))
|
||
|
(vector-set! vec pos (if (and (eq? stars '★★) (>= jmp 3))
|
||
|
(sub1 jmp)
|
||
|
(add1 jmp)))
|
||
|
(+ pos jmp))))
|
||
|
|