avoid parameters

master
Matthew Butterick 7 years ago
parent 59458827df
commit 11ee809772

@ -9,37 +9,37 @@
datum) datum)
#,@(cdr lines)))) #,@(cdr lines))))
(define vec #f)
(define (set-knot-range! int) (set! vec (list->vector (range int))))
(define-macro (#%mb STARS RANGE STR) (define-macro (#%mb STARS RANGE STR)
#`(#%module-begin #`(#%module-begin
(set-knot-range! RANGE) (set-knot-range! RANGE)
((if (eq? 'STARS ') one-star two-star) STR))) ((if (eq? 'STARS ') one-star two-star) STR)))
(define (one-star str) (define (one-star str)
(for ([len (in-port read (open-input-string (string-replace str "," " ")))]) (define lens (for/list ([len (in-port read (open-input-string (string-replace str "," " ")))])
(reverse-segment len)) len))
(reverse-segments lens)
(* (vector-ref vec 0) (vector-ref vec 1))) (* (vector-ref vec 0) (vector-ref vec 1)))
(define (two-star str) (define (two-star str)
(define ascii-chars (map char->integer (string->list str))) (define ascii-chars (map char->integer (string->list str)))
(for* ([round (in-range 64)] (reverse-segments (append ascii-chars '(17 31 73 47 23)) #:count 64)
[len (in-list (append ascii-chars '(17 31 73 47 23)))])
(reverse-segment len))
(define dense-hash (for/list ([i (in-range 16)]) (define dense-hash (for/list ([i (in-range 16)])
(apply bitwise-xor (for/list ([v (in-vector vec (* i 16) (* (add1 i) 16))]) (apply bitwise-xor (for/list ([v (in-vector vec (* i 16) (* (add1 i) 16))])
v)))) v))))
(string-append* (for/list ([num (in-list dense-hash)]) (string-append* (for/list ([num (in-list dense-hash)])
(~r num #:base 16 #:min-width 2 #:pad-string "0")))) (~r num #:base 16 #:min-width 2 #:pad-string "0"))))
(define vec #f)
(define current-position (make-parameter 0))
(define skip-size (make-parameter 0))
(define (set-knot-range! int) (set! vec (list->vector (range int))))
(define (reverse-segment len) (define (reverse-segments lens #:count [count 1])
(define posns (for/list ([i (in-range len)]) (for*/fold ([current-position 0]
(modulo (+ (current-position) i) (vector-length vec)))) [skip-size 0])
(for ([val (in-list (map (curry vector-ref vec) posns))] ([i (in-range count)]
[posn (in-list (reverse posns))]) [len (in-list lens)])
(vector-set! vec posn val)) (define posns (for/list ([i (in-range len)])
(current-position (+ (current-position) len (skip-size))) (modulo (+ current-position i) (vector-length vec))))
(skip-size (add1 (skip-size)))) (for ([val (in-list (map (curry vector-ref vec) posns))]
[posn (in-list (reverse posns))])
(vector-set! vec posn val))
(values (+ current-position len skip-size) (add1 skip-size))))