Determine if a string is collapsible: Difference between revisions

Add Refal
m (→‎{{header|Wren}}: Minor tidy)
(Add Refal)
 
(2 intermediate revisions by 2 users not shown)
Line 1,344:
readln;
end.</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func$ collapse s$ .
for c$ in strchars s$
if c$ <> cc$
r$ &= c$
.
cc$ = c$
.
return r$
.
s$[] &= ""
s$[] &= "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln "
s$[] &= "..1111111111111111111111111111111111111111111111111111111111111117777888"
s$[] &= "I never give 'em hell, I just tell the truth, and they think it's hell. "
s$[] &= " --- Harry S Truman "
for s$ in s$[]
print "«««" & s$ & "»»» (" & len s$ & ")"
r$ = collapse s$
print "«««" & r$ & "»»» (" & len r$ & ")"
print ""
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 3,288 ⟶ 3,312:
Length: 1 <<<A>>>
</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
, ('')
('"If I were two-faced, would I be wearing this '
'one?" --- Abraham Lincoln ')
('..11111111111111111111111111111111111111111111'
'11111111111111111117777888')
('I never give \'em hell, I just tell the truth, '
'and they think it\'s hell. ')
(' '
' --- Harry S Truman '): e.Strings
= <Each Show e.Strings>;
};
 
Each {
s.F = ;
s.F t.I e.X = <Mu s.F t.I> <Each s.F e.X>;
};
 
Brackets {
e.X, <Lenw e.X>: s.L e.X =
<Prout <Symb s.L> ': <<<' e.X '>>>'>;
};
 
Show {
(e.X) = <Brackets e.X>
<Brackets <Collapse e.X>>
<Prout>;
};
 
Collapse {
= ;
s.C s.C e.S = <Collapse s.C e.S>;
s.C e.S = s.C <Collapse e.S>;
};</syntaxhighlight>
{{out}}
<pre>0: <<<>>>
0: <<<>>>
 
72: <<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>>
70: <<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>>
 
72: <<<..1111111111111111111111111111111111111111111111111111111111111117777888>>>
4: <<<.178>>>
 
72: <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>>
69: <<<I never give 'em hel, I just tel the truth, and they think it's hel. >>>
 
72: <<< --- Harry S Truman >>>
17: <<< - Hary S Truman >>></pre>
 
=={{header|REXX}}==
Line 3,390 ⟶ 3,465:
 
=={{header|RPL}}==
{{trans|Kotlin}}
{{works with|Halcyon Calc|4.2.7}}
{{trans|Kotlin}}
{| class="wikitable"
! RPL code
Line 3,399 ⟶ 3,474:
≪ → string
≪ "" DUP
1 string SIZE '''FOR''' j
string j DUP SUB
'''IF''' DUP2 ≠ '''THEN'''
Line 3,406 ⟶ 3,481:
'''END''' DROP
'''NEXT''' DROP
≫ ≫ ‘'''<span style="color:blue">CLAPS</span>'''’ STO
|
'''<span style="color:blue">CLAPS</span>''' ''( "strrinng" -- "string" )''
output string = last = ""
scan the input string
Line 3,419 ⟶ 3,494:
|}
{{works with|HP|49}}
« → string
« { "" }
string SIZE 1 '''FOR''' j
string j DUP SUB SWAP
'''IF''' DUP2 HEAD == '''THEN''' NIP '''ELSE''' + '''END'''
-1 '''STEP'''
∑LIST
» » ‘'''<span style="color:blue">CLAPS</span>'''’ STO
When displaying strings, RPL always adds double quotes. To fulfill the artistic touch requirement, we have used guillemets to bracket Lincoln's statement.
≪ { ""
{{in}}
"≪ If I were two-faced, would I be wearing this one? ≫ --- Abraham Lincoln "
<pre>
"..1111111111111111111111111111111111111111111111111111111111111117777888"
≪ { ""
"I Ifnever Igive were'em two-facedhell, would I bejust wearingtell thisthe truth, one?and they ---think Abrahamit's Lincolnhell. "
" --- Harry S Truman " }
"..1111111111111111111111111111111111111111111111111111111111111117777888"
1 5 '''FOR''' j DUP j GET <span style="color:blue">CLAPS</span> SWAP '''NEXT''' DROP
"I never give 'em hell, I just tell the truth, and they think it's hell. "
≫ EVAL
" --- Harry S Truman " }
1 5 FOR j DUP j GET CLAPS SWAP NEXT DROP
≫ EVAL
</pre>
{{out}}
<pre>
2,099

edits