Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
trythis :- T = tree( tree( tree( nil, nil, 1 ), tree( nil, nil, 3 ), 2 ), tree( nil, tree( nil, nil, 6 ), 5 ), 4 ), sum(T,S), count(3,T,C), writeln(sum is S), writeln(count is C). sum( nil , 0 ). sum( tree(L,R,V) , S ) :- sum( L , SumL ), sum( R , SumR ), S is V + SumL + SumR . count( _, nil, 0 ). count( X, tree(L,R,V), C) :- count(X,L,Lefts), count(X,R,Rights), ( X = V -> N = 1 ; N = 0 ) , C is N + Lefts + Rights.