[BULK] [plt-scheme] Teaching Scheme

From: Samuel Williams (space.ship.traveller at gmail.com)
Date: Mon May 3 10:26:51 EDT 2010

Dear Stephen,

Can you let me know firstly which function is responsible for printing the output?

Secondly, can you add comments explaining how it works? I can generally appreciate what you are doing, but I'm not a Scheme programmer so I might not understand the exact detail correctly.

Thanks
Samuel

On 4/05/2010, at 1:01 AM, Stephen Bloch wrote:
> 
> Well, that particular algorithm relies very heavily on mutation, but here's a functional version.
> 
> (define (door-open door)
>   (doh door 99))
> 
> (define (doh door pass)
>   (cond [(zero? pass) true]
>         [(= (remainder door (+ pass 1)) pass)
>          (not (doh door (- pass 1)))]
>         [else
>          (doh door (- pass 1))]))
> 
> (define doors (build-list 100 door-open))
> 
> 
> 
> Somewhat shorter but more cryptic:
> 
> (define (door-open door)
>   (doh door 99))
> 
> (define (doh door pass)
>   (or (zero? pass)
>       (not (boolean=? (= (remainder door (+ pass 1)) pass)
>                       (doh door (- pass 1))))))
> 
> (define doors (build-list 100 door-open))
> 
> 
> 
> Even shorter, but takes some math (and illustrates how artificial this problem is :-) :
> 
> (define (door-open door)
>    (integer? (sqrt (+ door 1))))
> 
> (define doors (build-list 100 door-open))
> 
> 
> 
> Stephen Bloch
> sbloch at adelphi.edu
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100504/9755a7f7/attachment.html>

Posted on the users mailing list.