Find prime n such that reversed n is also prime: Difference between revisions

→‎{{header|RPL}}: straightforward approach
(→‎{{header|RPL}}: straightforward approach)
Line 1,331:
This program uses the words <code>RVSTR</code> and <code>BPRIM?</code>, respectively made to [[Reverse_a_string#RPL|revert a string]] and to [[Primality_by_trial_division#RPL|test primality by trial division]]
≪ { } 1 499 '''FOR''' n
'''IF''' n R→B '''<span style="color:blue">BPRIM?</span> THEN'''
'''IF''' n →STR '''<span style="color:blue">RVSTR'''</span> STR→ R→B <span style="color:blue">BPRIM?</span> '''BPRIM? THEN''' n + '''END'''
'''END'''
'''NEXT'''
≫ '<span style="color:blue">TASK</span>' STO
≫ EVAL
 
====Straightforward approach====
Numbers are here reversed without any string conversion.
{{works with|HP|49}}
« { }
1 499 '''FOR''' n
'''IF''' n ISPRIME? '''THEN'''
n 0
'''WHILE''' OVER '''REPEAT'''
SWAP 10 IDIV2 ROT 10 * +
'''END''' NIP
'''IF''' ISPRIME? '''THEN''' n + '''END'''
'''END'''
'''NEXT'''
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1,150

edits