Ask your own question, for FREE!
MIT 6.001 Structure and Interpretation of Computer Programs, Spring 2005 15 Online
OpenStudy (anonymous):

In the notes from lecture3 - the factorial example - might it be simpler for the ifact-helper to only keep track of 2 values instead of 3: (define ifact-helper(lambda(p c) (if (= c 1) p (ifact-helper (* p c) (- c 1)))))

OpenStudy (anonymous):

where ifact would be defined as (define ifact(lambda(n)(ifact-helper n (- n 1)))) -i found the way it was explained with the count maybe overcomplicating it

OpenStudy (anonymous):

Yes, I would prefer your solution. Simple to see how it multiplies n * (n - 1) * ... * 2. No need to drag the constant value of n along with ifact-helper parameters.

OpenStudy (anonymous):

Ohhhh, I see why the ifact-helper uses 3 values - one for product, one for counter, and one to remember the initial value - because in most iterative solutions, the product changes and you still need to remember the initial value to re-use in the operations at each iteration - it just happens in this case of the factorial where the initial value becomes irrelevant in the calculations

OpenStudy (anonymous):

Exactly! You are counting down from n - 1, so the iteration stops naturally at 1. In the lecture they are counting up, and need to remember when to stop.

OpenStudy (anonymous):

yes that is correct

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Breathless: Spooky witch but cute
6 hours ago 3 Replies 0 Medals
Arriyanalol: help
5 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
8 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
8 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!