0 Members and 3 Guests are viewing this topic.
:Ans→N --- find the AnsTh palprime:5→A:0→E:While 1:E+1→E:1+int(log(Ans→B:int(E10^(1-Ans:If prod(Ans-{1,3,7,9:End:E10^(B+1→F:E:For(G,B,1,{-}1:.1Ans→D:F+fPart(Ans)10^(G→F:int(D:End:10^(B→P:For(H,0,9:If fPart(F/3:Then:5:While Ans{^2}≤F and fPart(F/Ans) and fPart(F/(Ans+2:Ans+6:End:If Ans{^2}>F:Then:A+1→A:If A=N:Stop:End:End:F+P→F:End:End
:If prod(Ans-{1,3,7,9 Goes to::If 1<gcd(10,Ans ;I actually used 'not equal', but this works, too:If fPart(F/3 Goes to::If remainder(F,3:While Ans{^2}≤F and fPart(F/Ans) and fPart(F/(Ans+2 Goes to::While Ans{^2}≤F and min(remainder(F,{Ans,Ans+2
:DelVar EAns-5→N:While 1:E+1→E:1+int(log(E→B:If 1<gcd(10,int(E10^(1-Ans:End:10E→F:E→D:While iPart(D:.1iPart(D→D:10(F+fPart(Ans→F:End:For(H,0,9:If remainder(F,3:Then:√(F→D:7:While Ans≤D and min(remainder(F,{Ans,Ans+4:Ans+6:End:N-(Ans>D→N:If not(Ans:Return:End:End:F+10^(B→F:End:End
:DelVar EAns-5→N:While 1:E+1→E:1+int(log(E→B:If 1<gcd(10,int(E10^(1-Ans:End:10E→F:E→D:While iPart(D:.1iPart(D→D:10(F+fPart(Ans→F:End:For(H,0,9:If min(remainder(F,{3,7,11:Then:√(F→D:13:While Ans≤D and min(remainder(F,Ans+{0,4,6,10,16,18,24,28:Ans+30:End:N-(Ans>D→N:If not(Ans:Return:End:End:F+10^(B→F:End:End
:DelVar EAns-5→N:While 1:E+1→E:1+int(log(E→B:If 1<gcd(10,int(E10^(1-Ans:End:10E→F:E→D:While iPart(D:.1iPart(D→D:10(F+fPart(Ans→F:End:For(H,0,9:If fPart(F/3:Then:√(F→D:7:While Ans≤D and min(fPart(F/Ans+{0,4,6,10,12,16,22,24:Ans+30:End:N-(Ans>D→N:If not(Ans:Return:End:End:F+10^(B→F:End:End
So I tested yours and I got 21 seconds for the 42nd prime palindrome.
Compared to mine, yours is 53 bytes less, too. You have a bunch of places that can be optimised for speed, though, so I tried a few things and here is what I have:First, here are the main optimisations I made:Code: [Select]:If prod(Ans-{1,3,7,9 Goes to::If 1<gcd(10,Ans ;I actually used 'not equal', but this works, too:If fPart(F/3 Goes to::If remainder(F,3:While Ans{^2}≤F and fPart(F/Ans) and fPart(F/(Ans+2 Goes to::While Ans{^2}≤F and min(remainder(F,{Ans,Ans+2There are a few more, too, but here is what I ended up with:Code: [Select]:DelVar EAns-5→N:While 1:E+1→E:1+int(log(E→B:If 1<gcd(10,int(E10^(1-Ans:End:10E→F:E→D:While iPart(D:.1iPart(D→D:10(F+fPart(Ans→F:End:For(H,0,9:If remainder(F,3:Then:√(F→D:7:While Ans≤D and min(remainder(F,{Ans,Ans+4:Ans+6:End:N-(Ans>D→N:If not(Ans:Return:End:End:F+10^(B→F:End:EndNow it takes about 17 seconds to compute the 42nd prime palindrome and it is 24 bytes smaller
I have been trying to tweak it to get it even faster and I know that there must be a few optimisations that I am not seeing. It is 77 bytes smaller than mine and almost as fast, so that is really awesome....After adjusting the prime checker thing even more, I made it much faster, and it is now faster than mine, at the cost of some bytes (still 59 bytes smaller than mine). For comparison, the version above takes 17 seconds to find palprime 42 and 86 seconds for palprime 100. This version takes 13 and 52 seconds, respectively.Code: [Select]:DelVar EAns-5→N:While 1:E+1→E:1+int(log(E→B:If 1<gcd(10,int(E10^(1-Ans:End:10E→F:E→D:While iPart(D:.1iPart(D→D:10(F+fPart(Ans→F:End:For(H,0,9:If min(remainder(F,{3,7,11:Then:√(F→D:13:While Ans≤D and min(remainder(F,Ans+{0,4,6,10,16,18,24,28:Ans+30:End:N-(Ans>D→N:If not(Ans:Return:End:End:F+10^(B→F:End:EndHopefully everything is typed properly.EDIT: Made it even faster. Now 12 and 49 seconds respectively, using the same prime checking routine as my program.