Two identical strings: Difference between revisions

RPL: optimized version
(RPL: add section)
(RPL: optimized version)
Line 3,842:
 
=={{header|RPL}}==
===Slow version)===
Binary versions of numbers from 1 to 999 are converted into strings to check the half-half identity.
{{works with|Halcyon Calc|4.2.8}}
≪ R→B →STR 3 OVER SIZE 1 - SUB
Line 3,852 ⟶ 3,854:
≪ BIN { } 1 999 FOR n
'''IF''' n '''TWIN?''' '''THEN''' n →STR "=" + n R→B →STR 2 OVER SIZE 1 - SUB + + '''END NEXT'''
'''THEN''' n →STR "=" +
n R→B →STR 2 OVER SIZE 1 - SUB + + '''END NEXT'''
≫ ''''TASK'''' STO
{{out}}
Line 3,859 ⟶ 3,863:
</pre>
Runs on an HP-28S in 130 seconds.
=== Optimized version===
{{trans|FreeBASIC}}
40% of the code is dedicated to the display of the results.
{{works with|Halcyon Calc|4.2.8}}
{| class="wikitable"
! RPL code
! Comment
|-
|
≪ BIN { }
2 1
'''DO'''
'''IF''' DUP2 ≤ '''THEN''' OVER ROT + SWAP '''END'''
DUP2 * OVER +
4 ROLL OVER DUP →STR "=" +
SWAP R→B →STR 2 OVER SIZE 1 - SUB + + 4 ROLLD
SWAP 1 +
'''UNTIL''' SWAP 1000 ≥ '''END''' DROP2
≫ ''''TASK'''' STO
|
'''TASK''' ''( -- { "results" } )''
n = 1, p = 2
do
if n >= p then p = p + p
k = n + n * p
print "k= ";
print "bin(k)"
n = n + 1
loop until k ≥ 1000
|}
Runs on an HP-28S in 6 seconds.
 
=={{header|Ruby}}==
1,150

edits