Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
% SoE % p.175 Clocksin & Mellish + my early cut-off + addition/mod + odds % -- Will Ness p(N,[]):- N < 2, !. p(N,[2|R]):- i(3,N,L), s(N,L,R). i(A,B,[A|C]):- A=<B -> D is A+2, i(D,B,C). i(_,_,[]). s(_,[],[]). s(N,[A|B],[A|C]):- A*A =< N -> r(A,B,D), s(N,D,C) ; C=B. r(A,B,D):- M is A*A, r(A,M,B,D). r(_,_,[],[]). r(P,M,[A|B],C):- ( M>A -> C=[A|D], r(P,M,B,D) ; M==A -> M2 is M+2*P, r(P,M2,B,C) ; M<A -> C=[A|D], M2 is M+2*P, r(P,M2,B,D) % (?, but it works) ). % time( (p(104729,_X),length(_X,N),last(_X,Y),nth1(10000,_X,Z),!) ). % 2,074,616 inferences, 0.560 CPU in 0.560 seconds (100% CPU, 3707233 Lips) % time( (p(224729,_X),length(_X,N),last(_X,Y),nth1(19999,_X,Z),!) ). % 5,484,025 inferences, 1.409 CPU in 1.410 seconds (100% CPU, 3891427 Lips) %% logBase 2 => n^1.40 infs n^1.33 time % set_prolog_flag(stack_limit, 2_147_483_648), time( % (p(479909,_X),length(_X,N),last(_X,Y),nth1(40000,_X,Z),!) ). % 14,512,805 inferences, 3.692 CPU in 3.692 seconds (100% CPU, 3930865 Lips) %% logBase 2 => n^1.40 infs n^1.39 time