Anonymous user
Determine if a string is collapsible: Difference between revisions
m
→{{header|REXX}}: add semaphore.
(→{{header|REXX}}: marked incorrect) |
m (→{{header|REXX}}: add semaphore.) |
||
Line 1,414:
=={{header|REXX}}==
<lang rexx>/*REXX program "collapses" all immediately repeated characters in a string (or strings).*/
@.= /*define a default for the @. array. */
Line 1,429 ⟶ 1,428:
say copies('═', 105) /*show a separator line between outputs*/
if j>1 & L==0 then leave /*if arg is null and J>1, then leave. */
say ' length='right(L, 3) " input=«««" || @.j || '»»»'▼
new= collapse(@.j)
say 'string' word("isn't is",1+collapsible) 'collapsible' /*display semaphore value*/
▲ say ' length='right(L, 3) " input=«««" || @.j || '»»»'
w= length(new)
say ' length='right(w, 3) " output=«««" || new || '»»»'
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
collapse: procedure expose collapsible; parse arg y 1 $ 2
collapsible= y\==$; return $ /*set boolean to true if collapsible.*/</lang>
{{out|output|text= when using the internal default inputs:}}
<pre>
═════════════════════════════════════════════════════════════════════════════════════════════════════════
string isn't collapsible
length= 0 input=«««»»»
length= 0 output=«««»»»
═════════════════════════════════════════════════════════════════════════════════════════════════════════
string is collapsible
length= 72 input=«««"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln »»»
length= 70 output=«««"If I were two-faced, would I be wearing this one?" - Abraham Lincoln »»»
═════════════════════════════════════════════════════════════════════════════════════════════════════════
string is collapsible
length= 72 input=«««..1111111111111111111111111111111111111111111111111111111111111117777888»»»
length= 4 output=«««.178»»»
═════════════════════════════════════════════════════════════════════════════════════════════════════════
string is collapsible
length= 72 input=«««I never give 'em hell, I just tell the truth, and they think it's hell. »»»
length= 69 output=«««I never give 'em hel, I just tel the truth, and they think it's hel. »»»
═════════════════════════════════════════════════════════════════════════════════════════════════════════
string is collapsible
length= 72 input=««« --- Harry S Truman »»»
length= 17 output=««« - Hary S Truman »»»
|