[plt-scheme] Re: HTDP12.4.2

From: Marco Morazan (morazanm at gmail.com)
Date: Wed Jan 14 22:31:43 EST 2009

On Wed, Jan 14, 2009 at 10:09 PM, runyon avenue soldier
<runyonavenuesoldier at yahoo.com> wrote:
> ;;arrangements: a word-->a list of words
> ;;produces a list of all possible arrangements of a word
> ;;example--> (arrangements (list 'a 'b 'c)-->(list (list
>   (define (arrangements word)
>     (cond
>       ((empty? word) (list empty))
>        (else
>         (insert (first word) (arrangements (rest word))))))

Hmmm.....your example is not finished. It is quite important to
clearly state examples to solve this problem.

> ;;insert: a symbol and a list of words-->a list of words
> ;;to produce a list of words with the symbol inserted btwn all letters of
> the words in the list and at the beginning and end of the words.
> ;;example-->(list (list 'e 'r) (list 'r 'e))-->(list (list 'd 'e 'r) (list
> 'e 'd 'r) (list 'e 'r 'd) (list 'd 'r 'e) (list 'r 'd 'e) (list 'r 'e 'd))
>   (define (insert n alow)
>     (cond
>       ((empty? alow) null)
>        (else
>           (append (ins n (first alow))  (insert n (rest alow))))))

Your examples are incomplete.  What are you inserting into (list (list
'e 'r) (list 'r 'e))? Is it 'd? If so, the result looks promising.

> ;;ins: a symbol and a word-->a list of words
> ;;produces a list of words from the single word with the symbol inserted at
> all points in the word
> ;;example-->(ins n ('b 'c))--> (list (list 'n 'b 'c) (list 'b 'n 'c)  (list
> 'b 'c 'n))

What is ('b 'c)? Do you mean '(b c) ?

> ;;example-->(ins n ( 'w 'x 'y 'z))-->(list (list n w x y z) (list w n x y z)
> (list w x n y z) (list w x y n z) (list w x y z n))

What is ( 'w 'x 'y 'z) ? Do you mean '(w x y z) ?

>   (define (ins n word)
>     (cond
>       ((empty? word) (list n ))
>       (else
>          (......n (first word)
>                               (ins n (rest word))))))
> ive not been able to complete this last fnx because as i recur one letter
> gets losts.

The general idea for the results in your examples looks good. Let me
ask you a few questions:

1. What should the result be of evaluating (ins n (rest word)) ?
2. What is missing from every word in the result returned by (ins n
(rest word)) ? What do you need to do to add what is missing? Remember
that if the result is of arbitrary size, you need an auxiliary
3. What is missing from the result obtained from question 2? How do
you add what is missing?

I suggest you answer the above questions with examples first, before
trying to write any code.

Let us know if you need more help.

Enjoy the problem!

> ________________________________
> From: Marco Morazan <morazanm at gmail.com>
> To: runyon avenue soldier <runyonavenuesoldier at yahoo.com>
> Sent: Thursday, January 15, 2009 3:07:29 AM
> Subject: Re: HTDP12.4.2
> Sure, what have you done to solve the problem? Show us your work so far.
> On Wed, Jan 14, 2009 at 9:40 PM, runyon avenue soldier
> <runyonavenuesoldier at yahoo.com> wrote:
>> pls am a newbie in programming and am using HTDP but am stuck with
>> exercise
>> 12.4.2. I was wodering whether you could give me a hand.
> --
> Cheers,
> Marco




Posted on the users mailing list.