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}}==
{{incorrect|HQ9+|not consistent with the task's requirements which are a function which 'determines if a character string is collapsible' and 'if so collapses the string (by removing immediately repeated characters)}}
<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 /*get a value fromthe arg; get 1st char. */
do k=2 to length(y) /*traipse through almost all the chars.*/
_= substr(y, k, 1) /*pick a character from Y (1st arg). */
if _==right($, 1) then iterate /*Is this the /*Samesame character? Skip it.*/
$= $ || _ /*append char.the character, it's diffdifferent.*/
end /*j*/
collapsible= y\==$; return $ /*set boolean to true if collapsible.*/</lang>
{{out|output|text=&nbsp; 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 »»»