Lychrel numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(added RPL) |
||
Line 3,590: | Line 3,590: | ||
3 Lychrel palindromes: 4994 8778 9999 |
3 Lychrel palindromes: 4994 8778 9999 |
||
</pre> |
</pre> |
||
=={{header|RPL}}== |
|||
« 0 |
|||
'''WHILE''' OVER '''REPEAT''' 10 * SWAP 10 IDIV2 ROT + '''END''' |
|||
NIP |
|||
» '<span style="color:blue">IREVERSE</span>' STO |
|||
« { } DUP DUP2 500 0 → seeds related current palych stop counts |
|||
« 1 10000 '''FOR''' n |
|||
1 CF { } 'current' STO <span style="color:grey"> @ flag 1 set = loop has been exited before stop value</span> |
|||
n DUP <span style="color:blue">IREVERSE</span> |
|||
'''IF''' DUP2 == '''THEN''' 2 SF '''ELSE''' 2 CF '''END''' <span style="color:grey">@ flag 2 set = n is palindromic</span> |
|||
1 stop '''FOR''' j |
|||
+ 'current' OVER STO+ |
|||
'''IF''' related OVER POS '''THEN''' |
|||
'related' current STO+ 'counts' (0,1) STO+ |
|||
'''IF''' 2 FS? '''THEN''' 'palych' n STO+ '''END''' |
|||
1 SF stop 'j' STO |
|||
'''END''' |
|||
DUP <span style="color:blue">IREVERSE</span> |
|||
'''IF''' DUP2 == '''THEN''' 1 SF stop 'j' STO '''END''' |
|||
'''NEXT''' DROP2 |
|||
'''IF''' 1 FC? '''THEN''' |
|||
'related' current STO+ 'counts' 1 STO+ 'seeds' n STO+ |
|||
'''IF''' 2 FS? '''THEN''' 'palych' n STO+ '''END''' |
|||
'''END''' |
|||
'''NEXT''' |
|||
seeds counts palych |
|||
» » '<span style="color:blue">TASK</span>' STO |
|||
{{out}} |
|||
<pre> |
|||
3: {196 879 1997 7059 9999} |
|||
2: (5.,244.) |
|||
1: {4994 8778 9999} |
|||
</pre> |
|||
Results are identical when the loop limit is set at 50 instead of 500. |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |