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

I remember reading SICP. It's a lot of fun.

The recursive algorithm reminds me of something I was just looking at the other day, the Chu-Vandermonde identity.

One obvious way to speed it up is memoization. But I wonder if that would be as effective in this case as for Fibonacci.

Another way would be to just handle the penny case by just outputting 1 straight away if amount >= 0, and handle the penny-and-nickel case by outputting 1+floor(amount/5). I'd imagine that just doing this would speed up the program quite a bit.

But a straight-up, non-recursive calculation in one fell swoop? I'm not sure how to do that.