[plt-scheme] Permutation correct way to do it ?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri May 2 13:02:37 EDT 2008

But you're using an accumulator, violating the design recipe of the  
section in which the problem lives. 60%

-- Matthias




On Apr 30, 2008, at 5:22 AM, Rocky wrote:

>
> Matthias said:
>>                                     This exercise is within reach
>> for someone who has never programmed before and follows the recipe;
>> if you fall in this group, systematically use the recipe and you will
>> get there. It is a stumbling block for people who have programmed
>> before and believe that I made up the design recipe to torture them.
>
> It's so simple, so very simple, that only a child can do it!
>
> Look Ma, no append ...
> --rocky
>
>
> (define (arrange aword)
>   (cond
>     ((empty? aword) (cons empty empty))
>     (else (inter/all (first aword) (arrange (rest aword))))))
>
>
> (define (inter/all elem alist)
>   (cond
>     ((empty? alist) empty)
>     (else
>      (inter/one empty
>                 elem
>                 (first alist)
>                 (inter/all elem (rest alist))))))
>
>
> (define (inter/one worms elem can alist)
>   (cond
>     ((empty? can) (cons (stuff worms (cons elem empty)) alist))
>     (else
>      (cons (stuff worms (cons elem can))
>            (inter/one (cons (first can) worms)
>                       elem
>                       (rest can)
>                       alist)))))
>
>
> (define (stuff worms can)
>   (cond
>     ((empty? worms) can)
>     (else (stuff (rest worms) (cons (first worms) can)))))
>
>
>
>        
> ______________________________________________________________________ 
> ______________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile.  Try it now.  http:// 
> mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.