Compare length of two strings: Difference between revisions
Content added Content deleted
m (Simplify Common Lisp) |
|||
Line 2,009: | Line 2,009: | ||
</pre> |
</pre> |
||
=={{header|RPL}}== |
|||
{{works with|Halcyon Calc|4.2.7}} |
|||
{| class="wikitable" |
|||
! Code |
|||
! Comments |
|||
|- |
|||
| |
|||
≪ " [" OVER SIZE →STR "]" + + + |
|||
≫ ''''FormatString'''' STO |
|||
≪ |
|||
'''IF''' OVER SIZE OVER SIZE > '''THEN''' SWAP '''END''' |
|||
'''FormatString''' SWAP '''FormatString''' |
|||
≫ ''''SRT2S'''' STO |
|||
≪ |
|||
LIST→ → len |
|||
≪ len 1 '''FOR''' n |
|||
1 n 1 - '''START''' |
|||
'''IF''' OVER SIZE OVER SIZE < '''THEN''' SWAP '''END''' |
|||
n ROLLD |
|||
'''NEXT''' |
|||
n ROLLD |
|||
-1 '''STEP''' |
|||
1 len '''START''' len ROLL '''FormatString''' '''NEXT''' |
|||
≫ ≫ ''''SRTLS'''' STO |
|||
| |
|||
''( "string" -- "string [length]" )'' |
|||
''( "s1" "s2" -- "s1 [l1]" "s2 [l2]" )'' |
|||
Swap strings if necessary |
|||
Format strings |
|||
''( { strings } -- { strings } )'' |
|||
Push list in the stack |
|||
Use selection sort algorithm (favouring code size to execution time) |
|||
Format each string in the stack |
|||
|} |
|||
The following lines of code deliver what is required: |
|||
"AB" "ABCD" '''STR2S''' |
|||
{ "ABC" "AB" "ABCD" } '''SRTLS''' |
|||
{{out}} |
|||
<pre> |
|||
5: "ABCD [4]" |
|||
4: "AB [2]" |
|||
3: "ABCD [4]" |
|||
2: "ABC [3]" |
|||
1: "AB [2]" |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
<syntaxhighlight lang="ruby"> |
<syntaxhighlight lang="ruby"> |