Find prime n such that reversed n is also prime
Find prime n such that reversed n is also prime is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
- Task
Find prime n for that reversed n is also prime.
Let 0 < n < 500
Phix
<lang Phix>function rp(integer p) return is_prime(to_integer(reverse(sprint(p)))) end function for n=500 to 1000 by 500 do
sequence res = filter(get_primes_le(n),rp) string r = join_by(apply(true,sprintf,{{"%3d"},res}),1,floor(n/45)+6," ") printf(1,"%d reverse primes < %,d found:\n%s\n",{length(res),n,r})
end for</lang>
- Output:
34 reverse primes < 500 found: 2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389 56 reverse primes < 1,000 found: 2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389 701 709 727 733 739 743 751 757 761 769 787 797 907 919 929 937 941 953 967 971 983 991
Ring
<lang ring> load "stdlib.ring"
see "working..." + nl
row = 0 num = 0 limit = 500
for n = 1 to limit
strm = "" strn = string(n) for m = len(strn) to 1 step -1 strm = strm + strn[m] next strnum = number(strm) if isprime(n) and isprime(strnum) num = num + 1 row = row + 1 see "" + n + " " if row%10 = 0 see nl ok ok
next
see nl + "found " + num + " primes" + nl see "done..." + nl </lang>
- Output:
working... 2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389 found 34 primes done...