[racket] I don't understand structural recursion.

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Sat Sep 17 19:00:31 EDT 2011

Something else to think about is how you get from one answer to the next.

For example, it looks like (distinct-trees 2) is just (distinct-trees
1) with a new tree added as both a left and right child. Ask yourself
how (distinct-trees 3) is related to (distinct-trees 2), how
(distinct-trees 4) is related to (distinct-trees 3), etc.

Looks like a fun problem, where fun means I'm glad you're solving it,
and not me. :-)

Todd

On Sat, Sep 17, 2011 at 6:42 PM, Shriram Krishnamurthi <sk at cs.brown.edu> wrote:
> Hi Charlie,
>
> Yep, Catalan numbers!
>
> Here's something that may help.  Add the following two lines to the
> top of your file --
>
> #lang planet tracer/tracer
>
> (trace-all)
>
> -- and put a concrete call at the end, eg:
>
> (num-distinct-trees 3)
>
> Go to Language | Choose Language... and select the option at the top
> (Use the language declared in the source).  When you Run the program,
> this will fire up a browser window which will visualize the calls
> you're making and the answers they're returning, as trees.  (If you
> modify your program to return the actual trees, not just the counts,
> you can see them printed as values, too.)
>
> Shriram
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>



Posted on the users mailing list.