[plt-scheme] HtDP 26.1.2
* What does it mean to merge two neighbors:
(merge (list 1 3 9) (list 0 4 8))
-->
(list (list 0 1 3 4 8 9))
* Which design recipe applies?
* Work systematically and it all falls out.
On Mar 21, 2009, at 7:50 PM, David Yrueta wrote:
> Hi Matthias --
>
> Thank you for your response.
>
> I'm still a bit confused.
>
> How can this accomplished --
>
> (check-expect (merge-all-neighbors (list (list 9) (list 1))) (list
> (list 1 9)))?
>
> -- without some sorting going on within "merge-all-neighbors"?
>
> I would expect a function which only appended contiguous lists
> would evaluate like this --
>
> (check-expect (merge-all-neighbors (list (list 1) (list 9))) (list
> (list 1 9)))
> (check-expect (merge-all-neighbors (list (list 9) (list 1))) (list
> (list 9 1)))
>
> But instead, in both cases above, "merge-all-neighbors" returns
> (list (list 1 9)), yes?
>
> Where am I going wrong?
>
> Thanks!
> Dave
>
>
>
> On Sat, Mar 21, 2009 at 4:29 PM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>
> On Mar 21, 2009, at 6:26 PM, dave yrueta wrote:
>
> Hi all --
>
> Question about HtDP function "merge-neighbors:"
>
> Link to exercise: http://www.htdp.org/2003-09-26/Book/curriculum-Z-
> H-33.html#node_sec_26.1
>
> The text describes the contract for "merge-neighbors" as a function
> which "merges pairs of neighboring lists. More specifically, it
> consumes a list of lists (of numbers) and merges neighbors. For
> example,
>
> (equal? (merge-all-neighbors (list (list 2) (list 5) (list 9) (list
> 3)))
> (list (list 2 5) (list 3 9))) "
>
> In the example, however, it seems that in addition to merging pairs of
> neighboring lists, "merge-neighbors" also sorts each pair of lists in
> ascending order before combining them.
>
> No!
>
>
>
> In other words --
>
> (check-expect (merge-all-neighbors (list (list 9) (list 1)) (list
> (list 1 9))?
>
> This example wouldn't contradict the exercise. Indeed, it jives
> just fine.
>
>
>
> Further, suppose the function input is a list of list-of-numbers in
> descending order --
>
> (define list1 (list (list 9) (list 7) (list 5) (list 3))).
>
> In this case, does "merge-all-neighbors" evaluate list1 to (list (list
> 7 9) (list 3 5)) --
>
> This one obviously. But now run merge-all-neighbors on the result
> and see what you get.
>
> -- Matthias
>
>
> -- or to (list (list 3 5) (list 7 9)).
>
> That would be a function that merges neighbors and re-arranges
> things in addition.
>
>
>
>
> Thanks!
>
> Dave Yrueta
>
>
>
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090321/23e67bf7/attachment.html>