[racket] Generative recursion

From: David Yrueta (dyrueta at gmail.com)
Date: Sun Nov 7 11:42:59 EST 2010

If you've solved the permutations problem, then in my opinion, you have the
ability to solve any problem in the book.  Sounds like you're just having a
weird block.  Don't worry -- my guess is it happens to everyone!

The question Wooks put to you in one of his previous posts -- how can you
preserve the original value of n? -- is, I believe, the key to this
exercise.

Try writing a function which accepts a natural number n>0, and returns a
list of numbers from 1 to n, but with n leading each number on in the list:

;;test-function : number -> list-of-numbers
;;accepts n>0, returns a list-of-numbers from 1 to n with n leading each
number on the list
;;(check-expect (test-function 1) (list 1 1))
;;(check-expect (test-function 2) (list 2 1 2 2))
;;(check-expect (test-function 3) (list 3 1 3 2 3 3))

No tricks here -- this is a pretty straightforward function to design. If
you can do it, which I'm sure you can, then you've figured out how to write
a function which 1) preserves the original input, and 2) uses it as a
boundary condition to create a list of numbers.  From there you're only a
few minor tweeks away from the solution to tabulate-div -- and those minor
tweeks are present in your previous attempts.

When you figure out the solution, please don't post it to the list.  But if
you like, I'd be happy to look at it offline.

Good luck!

Dave Yrueta



On Sun, Nov 7, 2010 at 6:16 AM, Matthias Felleisen <matthias at ccs.neu.edu>wrote:

>
> On Nov 7, 2010, at 1:29 AM, Ken Hegeland wrote:
>
> >  I felt very dumb trying to figure this problem out.
>
>
> You shouldn't feel dumb. I suspect that this problem needs to go because it
> doesn't drive home the points I had had in mind when I wrote it. Sorry
>
> -- Matthias
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101107/09477fca/attachment.html>

Posted on the users mailing list.