a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment
bhrgunatha  ·  3155 days ago  ·  link  ·    ·  parent  ·  post: A nice problem from SICP

    But I wonder if that would be as effective in this case as for Fibonacci.

Sure, why not? It's still tree recursion after all. You just have to use an extra procedure that takes the change amount and how many coin values you have.

e.g. For the UK coin values are 1, 2, 5, 10, 20, 50, 100 and 200 so there are 8 coin values.

So instead of

    count_change(amount)

you'd use

    count_change(amount)

cc(amount, num_coins)

and you memoize cc with indexes of amount and num_coins