Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Can this be made tail-recursive in Prolog?
- counting_sum(0, 0).
- counting_sum(Num, Sum) :- Num > 0, PrevNum is Num - 1,
- counting_sum(PrevNum, PrevSum), Sum is Num + PrevSum.
- error(instantiation_error,(is)/2)
- counting_sum(Count, Sum):-
- counting_sum(Count, 0, Sum).
- counting_sum(0, Sum, Sum).
- counting_sum(Num, PrevSum, Sum):- Num > 0, PrevNum is Num - 1,
- NextSum is PrevSum + Num,
- counting_sum(PrevNum, NextSum, Sum).
Add Comment
Please, Sign In to add comment