Determine if a string is collapsible: Difference between revisions

add RPL
(Add Miranda)
(add RPL)
Line 3,320:
 
done...
</pre>
 
=={{header|RPL}}==
{{trans|Kotlin}}
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
≪ → string
≪ "" DUP
1 string SIZE '''FOR''' j
string j DUP SUB
'''IF''' DUP2 ≠ '''THEN'''
ROT OVER +
SWAP ROT
'''END''' DROP
'''NEXT''' DROP
≫ ≫ ‘'''CLAPS'''’ STO
|
'''CLAPS''' ''( "strrinng" -- "string" )''
output string = last = ""
scan the input string
c = jth character
if c ≠ last
output string += c
last = c
forget c or previous last
clean stack
|}
When displaying strings, RPL always adds double quotes. To fulfill the artistic touch requirement, we have used guillemets to bracket Lincoln's statement.
{{in}}
<pre>
≪ { ""
"≪ If I were two-faced, would I be wearing this one? ≫ --- Abraham Lincoln "
"..1111111111111111111111111111111111111111111111111111111111111117777888"
"I never give 'em hell, I just tell the truth, and they think it's hell. "
" --- Harry S Truman " }
1 5 FOR j DUP j GET CLAPS SWAP NEXT DROP
≫ EVAL
</pre>
{{out}}
<pre>
5: ""
4: "≪ If I were two-faced, would I be wearing this one? ≫ - Abraham Lincoln "
3: ".178"
2: "I never give 'em hel, I just tel the truth, and they think it's hel. "
1: " - Hary S Truman "
</pre>
 
1,150

edits