By the way, this is the code I have written, but can't get it to work:
divisor(X,Y) :- X < Y,0 is (Y mod X).
% auxiliar function:
% X = number, Y = divisor sum accumulator, Z = current divisor
perf(X,1,1).
perf(X,T,D) :- perf(X,Y,Z),divisor(D,X),T is (Y+D).
% main function:
perfect(X) :- perf(X,X,X).
Can someone rewrite it?
Don't bother fixing it, I have just done it myself:
divisor(X,Y) :- A is X, B is Y, X < Y, 0 is (B mod A).
perf(X,1,1).
perf(X,Y,Z) :- A is X, B is (Y-Z), C is (Z-1),C > 0, divisor(C+1,A),
perf(A,B,C).
perf(X,Y,Z) :- A is X, B is Y, C is (Z-1), C > 0, not(divisor(C+1,A)),
perf(A,B,C).
% main funct:
perfecto(X) :- T is X, T > 0, T is truncate(T), perf(T,T,T).
I'll probably have new problems for tomorrow. I'm looking forward to get
some assistance from you.
See ya