Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Anti-Loop
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
WJ  
View profile  
 More options May 4 2012, 6:27 am
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 4 May 2012 10:27:22 GMT
Local: Fri, May 4 2012 6:27 am
Subject: Re: Anti-Loop

WJ wrote:
> WJ wrote:

> > The low, loopy way:

> > (defparameter random (loop repeat 100 collect (random 10000)))

> > (loop for i in random
> >    counting (evenp i) into evens
> >    counting (oddp i) into odds
> >    summing i into total
> >    maximizing i into max
> >    minimizing i into min
> >    finally (return (list min max total evens odds)))

> > ==>
> > (47 9964 543718 46 54)

> > The high way:

> > (setq random (rand 10000 100))

> > (append
> >   (map (fn (f) (apply f random)) (list min max +))
> >   (map (fn (f) (length (filter f random))) (list even? odd?)))

> > ==>
> > (87 9996 522987 49 51)

> Racket:

> (define +random+ (map random (make-list 100 10000)))

> (map (lambda (x) (eval `(,@x +random+)))
>      '((argmin identity)
>        (argmax identity)
>        (foldl + 0)
>        (count even?)
>        (count odd?)))

> ==>
> '(64 9987 526998 50 50)

(for/fold
  ([mini 10000]
   [maxi -1]
   [sum 0]
   [evens 0]
   [odds 0])
  ([n +random+])
    (values
      [min mini n]
      [max maxi n]
      [+ sum n]
      [+ evens (if (even? n) 1 0)]
      [+ odds (if (odd? n) 1 0)]))

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.