[ prog / sol / mona ]

prog


How can I run my own instance of this

64 2020-02-22 23:53

[1/2]
Since your BIOS is being a Basic Inducer Of Suffering, here is an implementation of >>57 to eliminate delete-duplicates, in the MIT/GNU Scheme 9.1.1 from the Ubuntu LTS, while keeping as much of your structure as possible:

(define (posts-range range)
  (define (expand-range x)
    (cond ((> (length x) 1)
           (let* ((a (string->number (car x)))
                  (b (string->number (cadr x)))
                  (low (if (> a *max-posts*) *max-posts* a))
                  (high (if (> b *max-posts*) *max-posts* b))
                  (count (+ (- high low) 1)))
             (if (> high low)
                 (lambda () (iota count low))
                 (lambda () (list low)))))
          (else (let* ((a (string->number (car x)))
                       (low (if (> a *max-posts*) *max-posts* a)))
                  (lambda () (list low))))))
  (define (invoke-loop-set vector lamb)
    (for-each (lambda (e) (vector-set! vector e #t))
              (lamb)))
  (let* ((r1 (string-split range #\,))
         (r2 (map (lambda (x) (string-split x #\-)) r1))
         (r3 (map expand-range r2))
         (vec (make-vector (+ *max-posts* 1) #f)))
    (for-each (lambda (e) (invoke-loop-set vec e))
              r3)
    vec))

Here are some tests, keeping in mind that posts-range runs after the regex match:

1 ]=> (posts-range "1,3,5,7,290-300")
;Value 13: #(#f #t #f #t #f #t #f #t #f #f #f #f [...] #f #f #f #f #t #t #t #t #t #t #t #t #t #t #t)
1 ]=> (posts-range "1-9999999999")
;Value 14: #(#f #t #t #t #t #t #t #t #t #t #t #t [...] #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t)
1 ]=> (define fulltest (apply string-append (cons "1-300" (make-list (quotient (- 4096 7) 6) ",1-300"))))

At this point fulltest is >>50.

1 ]=> (posts-range fulltest)
;Value 17: #(#f #t #t #t #t #t #t #t #t #t #t #t [...] #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t)
1 ]=> (define (timeit proc)
   (with-timings proc
      (lambda (run-time gc-time real-time)
         (write (internal-time/ticks->seconds run-time))
         (write-char #\space)
         (write (internal-time/ticks->seconds gc-time))
         (write-char #\space)
         (write (internal-time/ticks->seconds real-time))
         (newline))))
1 ]=> (timeit (lambda () (posts-range "1,3,5,7,290-300")))
0. 0. 0.
1 ]=> (timeit (lambda () (posts-range fulltest)))
.04 0. .044
301


VIP:

do not edit these