Kaprekar numbers: Difference between revisions

Content added Content deleted
mNo edit summary
Line 4,676: Line 4,676:
5 : 99
5 : 99
total kaprekar numbers under 200 = 5
total kaprekar numbers under 200 = 5
</pre>

=={{header|RPL}}==
{{trans|Python}}
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
≪ DUP SQ →STR DUP SIZE → n n2 n2s
≪ 1 CF 1 n2s 1 - '''FOR''' j
'''IF''' n2 j 1 + n2s SUB STR→ '''THEN'''
LAST n2 1 j SUB STR→
'''IF''' DUP2 + n ==
'''THEN''' 1 SF n2s 'j' STO '''ELSE''' DROP2 '''END'''
'''END'''
'''NEXT'''
'''IF''' 1 FS?
'''THEN''' n →STR "=" + SWAP →STR + "+" + SWAP →STR +
'''ELSE''' "" '''END'''
≫ ≫ ''''KPREK'''' STO
≪ { 1 } 9 10000 '''FOR''' n 0 1 '''FOR''' k
n k + '''KPREK''' IF DUP "" ≠ '''THEN''' + '''ELSE''' DROP '''END'''
'''NEXT''' 9 '''STEP'''
≫ ''''TASK'''' STO
|
'''KPREK''' ''( n -- string )''
Examine all the possible a|b cuts of n²
if b is not zero
restore b in stack and get a
if a + b == n
then exit loop
if a and b found
then edit result
else return an empty string
'''TASK''': Loop ad examine
only numbers mod 9 = 0 or 1 (see Maple section)
|}
{{out}}
<pre>
1: { 1 "9=8+1" "45=20+25" "55=30+25" "99=98+1" "297=88+209" "703=494+209" "999=998+1" "2223=494+1729" "2728=744+1984" "4879=238+4641" "4950=2450+2500" "5050=2550+2500" "5292=28+5264" "7272=5288+1984" "7777=6048+1729" "9999=9998+1" }
</pre>
</pre>