[plt-scheme] HtDP 26.1.2
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