Find prime n such that reversed n is also prime: Difference between revisions
Find prime n such that reversed n is also prime (view source)
Revision as of 12:00, 21 September 2023
, 8 months ago→{{header|RPL}}: straightforward approach
(→{{header|Ruby}}: Add Ruby) |
(→{{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 '
'''IF''' n →STR
'''END'''
'''NEXT'''
≫ '<span style="color:blue">TASK</span>' STO
====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>
|