[racket] Is there a better way to do this in Racket?

From: Eli Barzilay (eli at barzilay.org)
Date: Sun May 13 17:52:16 EDT 2012

Just now, Harry Spier wrote:
> Thanks Neil,
> Each vector is in the order of about a thousand cells and there are
> about a thousand of these vectors that are processed at one time.
> So as long as I can do that in 10 or 20 seconds thats fine.  So as
> long as its "relatively efficient" I think I'm OK.  Whats just as
> important to me, is "clarity of the code", so that when I go back
> and look at this and other code six months from now I can still
> figure out what I did.

(These are relatively small numbers...)

In any case, here's a solution that is not meant to be used as-is, but
it makes a good point to consider the nature of your problem...  (If
efficiency does become an issue, then it would be better to work with
bytestrings instead of vectors anyway.)

  (define (list-of-ranges-of-ones v)
    (let* ([t (vector->list v)]
           [t (map (λ (x) (integer->char (+ 32 (* x 17)))) t)]
           [t (list->string t)]
           [t (regexp-match-positions* #rx"1+" t)]
           [t (map (λ (x) (list (car x) (sub1 (cdr x)))) t)])

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.