[racket] Challenge: <impressive function> in 140 chars or less

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Thu Feb 23 13:04:50 EST 2012

On Thu, Feb 23, 2012 at 11:47 AM, Prabhakar Ragde <plragde at uwaterloo.ca> wrote:
> Neil Toronto wrote:
>> What's your favorite not just computable, but tweetable function?
> (define (r n)
>  (for/fold ([s 1] [l '()]) ([i n])
>    (values (/ 1 (- (* 2 (floor s)) s -1)) (cons s l))))
> I tweeted this to make sure it fit. I had 23 characters to spare, could
> squeeze a bit of whitespace out, then use the rest to make it more elegant,
> but I have actual work to do... --PR

What is this thing? It seems coolly symmetric in this view:

(require plot)
(plot (points (let-values ([(n l) (r (expt 2 12))])
                (for/list ([i (in-naturals)]
                           [x (in-list l)])
                  (vector i x)))))

Posted on the users mailing list.