Hi Peter,
When accumulating you will still have to do the multiplications in the same
order. If you want to accumulate a list of the intermediate steps, you
cannot start with the bigger numbers and multiply down to the smaller
numbers. The recursion is masking the fact that the smaller numbers are
really getting multiplied first.
So, you should count up in your accumulator rather than down. Here's a
solution:
fun {FactLoop I N Acc}
if I==N
then Acc
else {FactLoop I+1 N I*Acc.1|Acc}
end
fun {Fact N}
{FactLoop 1 N [1]}
end
Your accumulator starts with the smallest value of 1, and you count up until
you reach the biggest value.
- Lyle
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users