/*
tail recursive versions:
*/

count(L,N) :- count(L,0,N).

count([], N,N).
count([_|Tail], Nsofar, N) :- N1 is Nsofar+1, count(Tail, N1, N).


sum(L,Sum) :- sum(L, 0, Sum).

sum([], Sum, Sum). 
sum([Head|Tail], SumSoFar, Total) :- S1 is SumSoFar + Head, sum(Tail, S1, Total).
								

average(List, Average) :- sum(List, Sum), count(List, Count), Average is Sum/Count.
