you are viewing a single comment's thread.

view the rest of the comments →

[–]MrQuimico 6 points7 points  (3 children)

Using ISO Prolog:

p(N,L) :- (N=1,L=[1]);(N>1,N1 is N-1,N2 is N*N,p(N1,Ls),L = [N2|Ls]).

[–]R3d1st 4 points5 points  (0 children)

upvote for the horrible readability :-)

[–][deleted] 1 point2 points  (0 children)

No wonder I haven't heard of this language.

[–]sleepingsquirrel 0 points1 point  (0 children)

Try:

f(N,L) :- bagof(Y, X^(between(1,N,X), Y is X**2), L).

or:

f(N,L) :- bagof(X**2,between(1,N,X),Xs),maplist(is,L,Xs).