|
|
@ -4,17 +4,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (#%mb (STARS) (STR) ...)
|
|
|
|
(define-macro (#%mb (STARS) (STR) ...)
|
|
|
|
#`(#%module-begin
|
|
|
|
#`(#%module-begin
|
|
|
|
((if (eq? 'STARS '★) one-star two-star) (format "~a" 'STR)) ...))
|
|
|
|
(time ((if (eq? 'STARS '★) one-star two-star) (format "~a" 'STR))) ...))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (knot-hashes str)
|
|
|
|
|
|
|
|
(for/list ([i (in-range 128)])
|
|
|
|
|
|
|
|
(knot-hash (format "~a-~a" str i))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (one-star str)
|
|
|
|
(define (one-star str)
|
|
|
|
(for*/sum ([i (in-range 128)]
|
|
|
|
(for*/sum ([kh (in-list (knot-hashes str))]
|
|
|
|
[digit (in-list (kh->ints (knot-hash (format "~a-~a" str i))))])
|
|
|
|
[int (in-list (kh->ints kh))])
|
|
|
|
digit))
|
|
|
|
int))
|
|
|
|
|
|
|
|
|
|
|
|
(define (two-star str)
|
|
|
|
(define (two-star str)
|
|
|
|
(define vec (for*/vector ([i (in-range 128)]
|
|
|
|
(define vec (for*/vector ([kh (in-list (knot-hashes str))]
|
|
|
|
[int (in-list (kh->ints (knot-hash (format "~a-~a" str i))))])
|
|
|
|
[int (in-list (kh->ints kh))])
|
|
|
|
(if (= int 1) "#" ".")))
|
|
|
|
(if (= int 1) 'used 'empty)))
|
|
|
|
(define (at-left-edge? idx) (= (modulo idx 128) 0))
|
|
|
|
(define (at-left-edge? idx) (= (modulo idx 128) 0))
|
|
|
|
(define (at-right-edge? idx) (= (modulo idx 128) 127))
|
|
|
|
(define (at-right-edge? idx) (= (modulo idx 128) 127))
|
|
|
|
(for/fold ([region 0])
|
|
|
|
(for/fold ([region 0])
|
|
|
@ -22,11 +26,12 @@
|
|
|
|
#:unless (number? val))
|
|
|
|
#:unless (number? val))
|
|
|
|
(let loop ([idx idx])
|
|
|
|
(let loop ([idx idx])
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
[(and (< -1 idx (vector-length vec)) (equal? (vector-ref vec idx) "#"))
|
|
|
|
[(and (<= 0 idx (sub1 (vector-length vec))) (eq? (vector-ref vec idx) 'used))
|
|
|
|
(vector-set! vec idx region)
|
|
|
|
(vector-set! vec idx region)
|
|
|
|
(unless (at-left-edge? idx) (loop (sub1 idx)))
|
|
|
|
(unless (at-left-edge? idx) (loop (sub1 idx)))
|
|
|
|
(unless (at-right-edge? idx) (loop (add1 idx)))
|
|
|
|
(unless (at-right-edge? idx) (loop (add1 idx)))
|
|
|
|
(map loop (list (+ idx 128) (- idx 128)))
|
|
|
|
(loop (+ idx 128))
|
|
|
|
|
|
|
|
(loop (- idx 128))
|
|
|
|
(add1 region)]
|
|
|
|
(add1 region)]
|
|
|
|
[else region]))))
|
|
|
|
[else region]))))
|
|
|
|
|
|
|
|
|
|
|
@ -34,7 +39,7 @@
|
|
|
|
(for*/list ([c (in-string kh)]
|
|
|
|
(for*/list ([c (in-string kh)]
|
|
|
|
[num (in-value (string->number (string c) 16))]
|
|
|
|
[num (in-value (string->number (string c) 16))]
|
|
|
|
[c (in-string (~r num #:base 2 #:min-width 4 #:pad-string "0"))])
|
|
|
|
[c (in-string (~r num #:base 2 #:min-width 4 #:pad-string "0"))])
|
|
|
|
(string->number (string c))))
|
|
|
|
(if (char=? c #\1) 1 0)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (knot-hash seed-str [range-in 256])
|
|
|
|
(define (knot-hash seed-str [range-in 256])
|
|
|
|
(define ascii-chars (map char->integer (string->list seed-str)))
|
|
|
|
(define ascii-chars (map char->integer (string->list seed-str)))
|
|
|
@ -52,7 +57,7 @@
|
|
|
|
[len (in-list lens)])
|
|
|
|
[len (in-list lens)])
|
|
|
|
(define posns (for/list ([i (in-range len)])
|
|
|
|
(define posns (for/list ([i (in-range len)])
|
|
|
|
(modulo (+ current-position i) range-in)))
|
|
|
|
(modulo (+ current-position i) range-in)))
|
|
|
|
(for ([val (in-list (map (curry vector-ref vec) posns))]
|
|
|
|
(for ([val (in-list (map (λ (posn) (vector-ref vec posn)) posns))]
|
|
|
|
[posn (in-list (reverse posns))])
|
|
|
|
[posn (in-list (reverse posns))])
|
|
|
|
(vector-set! vec posn val))
|
|
|
|
(vector-set! vec posn val))
|
|
|
|
(values (+ current-position len skip-size) (add1 skip-size)))
|
|
|
|
(values (+ current-position len skip-size) (add1 skip-size)))
|
|
|
|