8000 SICP - Solution: Exercise 1.14 · Issue #39 · sgignoux/sicp-solutions.net · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

SICP - Solution: Exercise 1.14 #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MartinMihalev opened this issue Oct 31, 2024 · 2 comments
Open

SICP - Solution: Exercise 1.14 #39

MartinMihalev opened this issue Oct 31, 2024 · 2 comments

Comments

@MartinMihalev
Copy link

First I want to say thank you for the detailed explanation of the exercise that really helped me to wrap my head around the problem. I found though a little issue with the formula $$T(n,2) = \frac{n^2-3n}5+1$$. When n=12 it results in 22.6 which is more than twice as less the correct answer 49(as seen on the image). Although math is not of my strengths I suspected that starting the summation with index of zero is somehow wrong and I ended up with the following formula:

$$T(n,2) = Ceil\left(\frac n5\right)+1+\sum_{i=1}^{Ceil(n/5)}T(n-5(i-1),2)$$

From this formula I derive two, because of the ceiling. When the amount is divisible by 5 without reminder:

$$T(n,2) = \left(\frac n5\right)+1+\sum_{i=1}^{n/5}T(n-5(i-1),2)$$ $$T(n,2) = \frac{n^2+7n}5+1$$

With reminder:

$$T(n,2) = \left(\frac n5+1\right)+1+\sum_{i=1}^{(n/5)+1}T(n-5(i-1),2)$$ $$T(n,2) = \frac{n^2+7n}5+3$$

The latter one gives as result 48,6 $$\approx$$ 49 when the amount is 12. The former one gives correctly 35 when the amount is 10. I hope that is helpful. Thank you again for sharing this valuable knowledge.

@ghost
Copy link
ghost commented Nov 8, 2024

I found a different issue but it's related to the same exercises.

When calculating the number of calls of the cc function for kind of coins = 2, or T(n,2), I would expect the number of green nodes to be ceil of (n/5), rather than floor.
Am I correct or am I missing something?

@MartinMihalev
Copy link
Author

I found a different issue but it's related to the same exercises.

When calculating the number of calls of the cc function for kind of coins = 2, or T(n,2), I would expect the number of green nodes to be ceil of (n/5), rather than floor. Am I correct or am I missing something?

I think you are correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0