[plt-scheme] HtDP: Another question on 10.1.9

From: Grant Rettke (grettke at acm.org)
Date: Fri Sep 19 13:51:35 EDT 2008

Hi,

I think I may have abused a recipe to come up with the solution for
10.1.9. Here is what I mean, my friend solved it like this:

(cons <first part>
      (cons <second part>
            (cons 'and
                  (cons <third part>
                        (cons <fourth part> empty)))))

This clearly works fine.

I followed (abused?) a recipe by using cond and having the first
clause handle any amount under 100. It looks like this:

(cond
    [(< n 100) <cents part goes here>]
    [else (cons <dollar amount and natural recusion occur here>)])

As long as the user provides >= 100, the expectation of a 5 items list is met.

However, does the solution need to be recursive? Did I over do it?

Best wishes,

Grant


Posted on the users mailing list.