[plt-scheme] HtDP 26.1.2

From: dave yrueta (dyrueta at gmail.com)
Date: Sat Mar 21 18:26:58 EDT 2009

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.  In other words --

(check-expect (merge-all-neighbors (list (list 9) (list 1)) (list
(list 1 9))?

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)) --

-- or to (list (list 3 5) (list 7 9)).

Thanks!

Dave Yrueta







Posted on the users mailing list.