Hi Sam --<div><br></div><div>As Jos commented, this is a very tough exercise, but it looks like you're off to a good start. </div><div><br></div><div>The most obvious problem with your current solution lies with 'insert-everywhere/in-single-word.' My first suggestion is to check the function examples to make sure the values they expect are consistent with your data definitions. </div>
<div><br></div><div>Dave</div><div><br></div><div><br></div><div><br><div class="gmail_quote">On Tue, Jul 6, 2010 at 1:15 PM, Jos Koot <span dir="ltr"><<a href="mailto:jos.koot@telefonica.net">jos.koot@telefonica.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Exercise 12.4.2 is notorius. When looking to (list 'a 'b 'c), you should<br>
exspect 6 distinct permutations.<br>
<font color="#888888">Jos<br>
</font><div><div></div><div class="h5"><br>
> -----Original Message-----<br>
> From: <a href="mailto:users-bounces@racket-lang.org">users-bounces@racket-lang.org</a><br>
> [mailto:<a href="mailto:users-bounces@racket-lang.org">users-bounces@racket-lang.org</a>] On Behalf Of Sam Griff<br>
> Sent: 06 July 2010 20:00<br>
> To: <a href="mailto:users@racket-lang.org">users@racket-lang.org</a><br>
> Subject: [racket] [htdp] Help with Exercise 12.4.2<br>
><br>
> Hello. Like many others working through HtDP I have hit the<br>
> wall at this exercise. I'm not sure what I have so far is in<br>
> line with the "proper" way to do this exercise and would<br>
> appreciate any help/suggestions. Here is the code I have so far:<br>
><br>
> ;; A list of words is either<br>
> ;; 1. empty<br>
> ;; 2. (cons w low)<br>
> ;; where w is a word and low is a list of words<br>
><br>
> ;; arrangements : word -> list-of-words ;; to create a list<br>
> of all rearrangements of the letters in a-word (define<br>
> (arrangements a-word)<br>
> (cond<br>
> [(empty? a-word) (cons empty empty)]<br>
> [else (insert-everywhere/in-all-words (first a-word)<br>
> (arrangements (rest a-word)))]))<br>
><br>
> ;; Contract:<br>
> ;; insert-everywhere/in-single-word : symbol word -><br>
> list-of-words ;; Purpose:<br>
> ;; to insert a symbol everywhere in a single word ;; Examples:<br>
> ;; (insert-everywhere/in-single-word 'a empty) should produce<br>
> (list 'a) ;; (insert-everywhere/in-single-word 'b (list 'a))<br>
> should produce (list (list 'a 'b) (list 'b 'a)) ;;<br>
> (insert-everywhere/in-single-word 'c (list 'a 'b)) should<br>
> produce (list (list 'c 'a 'b) (list 'a 'c 'b) (list 'a 'b<br>
> 'c)) ;; Template:<br>
> ;; (define (insert-everywhere/in-single-word s w)<br>
> ;; (cond<br>
> ;; [(empty? w) ...]<br>
> ;; [else ... (first w) ...<br>
> (insert-everywhere/in-single-word s w) ...]))<br>
> (define (insert-everywhere/in-single-word s w)<br>
> (cond<br>
> [(empty? w) (list s)]<br>
> [else (list (list s (first w)) (cons (first w)<br>
> (insert-everywhere/in-single-word s (rest w))))]))<br>
><br>
> ;; insert-everywhere/in-all-words : symbol list-of-words -><br>
> list-of-words ;; to insert a symbol everywhere in a list of<br>
> words (define (insert-everywhere/in-all-words s low)<br>
> (cond<br>
> [(empty? low) empty]<br>
> [else (append (insert-everywhere/in-single-word s (first<br>
> low)) (insert-everywhere/in-all-words s (rest low)))]))<br>
><br>
><br>
> ;; Tests:<br>
> (define testword1 (list 'a))<br>
> (define testword2 (list 'a 'b))<br>
> (check-expect (insert-everywhere/in-single-word 'a empty)<br>
> (list 'a)) (check-expect (insert-everywhere/in-single-word 'b<br>
> testword1) (list (list 'b 'a) (list 'a 'b))) (check-expect<br>
> (insert-everywhere/in-single-word 'c testword2) (list (list<br>
> 'c 'a 'b) (list 'a 'c 'b) (list 'a 'b 'c)))<br>
><br>
><br>
> Thanks,<br>
><br>
> Sam<br>
> _________________________________________________<br>
> For list-related administrative tasks:<br>
> <a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
<br>
<br>
_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
</div></div></blockquote></div><br></div>