How it works: Define palprime(n)= Func :If n=1:Return 2:If n=2:Return 3:If n=3:Return 5:If n=4:Return 7:If n=5:Return 11 The first 5 palprimes are hardcoded, as my algorithm can not calculate them The algorithm itself works by generating palidrome numbers and then checking for primality. :Local z,u,p,o,d,t,p,i,c Local all the variables we need :z:=5 This variable indicatates the number of palprimes found :d:=0 This variable contains a number where we generate a palidrome from :Loop : d:=d+1 The number gets incremented with one every loop : u:=dim(string(d)) What's the size (how many characters) of that number? : If h≠1 and h≠3 and h≠7 and h≠9|h=intDiv(d,10^(u-1)):Cycle If the first character of this number is not 1, 3, 7 or 9, the number can NEVER be a palprime, so it jumps back to the start of the loop : t:=d*10^(u+1) : o:=d : For p,1,u : t:=t+mod(o,10)*10^(u-p) : o:=intDiv(o,10) : EndFor Create the palidrome number. If d is 123 for example, t will become 1230321. : p:=10^(u) in p we store the number that we need to add to t in order to calculate the next palidrome number. So for 1230321 that would be 1000 (the next numbers are 1231321, 1232321, etc) : For i,0,9 we need to loop 1O times (for example 1230321 to 1239321) : c:=5 To test primality, we are going to generate possible primes and divide the palidrome prime with it. The format of these possible primes is 6n-1 and 6n+1. I put c to 5 as that's 6 * 1 -1 (if n would be 1). : If mod(t,3)≠0 Then First I check if I can't devide by 3 (that's something I can't catch with (6n-1 and 6n+1) : While c*c≤t and mod(t,c)≠0 and mod(t,c+2)≠0 : c:=c+6 : EndWhile Here I loop through all the possible palidrome primes (for as long as 6n-1 is smaller than the square of the palidrome I'm testing) I check if I can devide the palidrome number by c (6n-1) and c+2 (6n+1). If not, add 6 to c. : If c*c>t Then : z:=z+1 : If z=n:Return t : EndIf If we got out of the loop, check if it's because we found a prime. If so, check if it's the nth. If that's the case return it. : EndIf : t:=t+p Here we calculate the next palidrome number in our range. If the current palidrome would be 1235321 we add 1000 to get 1236321 : EndFor if we looped through all the ranges (for example 1230321 to 1239321) go back to the start of the loop. There we will create 1240421 :EndLoop :EndFunc