The #SICP example of counting change (page 51 of the PDF) is kicking my butt, ha. It took me a really long time to understand that "using all n kinds of coins" means "you can choose freely from all the n available types of coins but don't need to use all of them". And now, as a challenge, I'm trying to come up with an iterative process to solve this and I'm really struggling!
No one said that studying computer science at 42yo would be easy 😌
=> More informations about this toot | More toots from gosha@merveilles.town
Oooh it's dynamic programming™
=> More informations about this toot | More toots from gosha@merveilles.town
Had to go learn to use let, iterations, and vectors to come up with that one, but it works.
=> More informations about this toot | More toots from gosha@merveilles.town
Or just use a do instead of a named let!
=> More informations about this toot | More toots from gosha@merveilles.town
@gosha is the exercise supposed to be done with recursion or it does not matter?
=> More informations about this toot | More toots from kototama@merveilles.town
@kototama It's not an exercise per se, but a challenge that follows an example. The example is of a recursive tree algorithm for solving the same problem, but it's very inefficient because it recomputes identical subtrees many times. And the challenge is to come up with a more efficient algorithm. In a previous example, this is done via a tail recursive procedure, but here I couldn't come up with a way to do that. The only other alternative I could find was to use memoization on the original tree recursive algorithm, but that's a bit too obvious... so searching further I landed on dynamic programming, which I learned when I was grinding leetcode for job interviews last year. It's likely not what the authors intended!
=> More informations about this toot | More toots from gosha@merveilles.town
@gosha ah thanks. I always confused them both a bit :-)
=> More informations about this toot | More toots from kototama@merveilles.town
@kototama Me too!
=> More informations about this toot | More toots from gosha@merveilles.town
@gosha shouldn't the iterative approach still use recursion?
=> More informations about this toot | More toots from fkinoshita@merveilles.town
@fkinoshita I thought so too but couldn't come up with one! How did you go about it?
=> More informations about this toot | More toots from gosha@merveilles.town
@gosha i also couldn't figure out for this exercise, i was hopeful you had another implementation!
=> More informations about this toot | More toots from fkinoshita@merveilles.town This content has been proxied by September (3851b).Proxy Information
text/gemini