1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!/usr/bin/env auto-editor palet
#lang palet
(define (remove-large! arr lim replace with)
(define start-p 0)
(define active #f)
(define j 0)
(for ([item arr])
(if (equal? item replace)
(begin
(when (not active)
(set! start-p j)
(set! active #t)
)
(when (and (equal? j (sub1 (len arr))) (>= (- j start-p) lim))
(array-splice! arr with start-p)
)
)
(when active
(when (> (- j start-p) lim)
(array-splice! arr with start-p j)
)
(set! active #f)
)
)
(incf j)
)
)
(define (maxclip oarr min)
(define arr (array-copy oarr))
(remove-large! arr min 1 0)
arr
)
(define (maxcut oarr min)
(define arr (array-copy oarr))
(remove-large! arr min 0 1)
arr
)
(define my-arr (bool-array 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 1))
(assert (equal?
(maxcut my-arr 3)
(bool-array 1 0 1 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
))
(define (b x) (>= x 0.5))
(define arr (array 'float64 0.1 0.2 0.3 0.6 0.7))
(assert (bool-array? (map b arr)))
|