Determine if a string is collapsible: Difference between revisions

Add CLU
No edit summary
(Add CLU)
Line 1,058:
becomes: <<< - Hary S Truman >>> (len 17)
</pre>
 
=={{header|CLU}}==
<lang clu>% Collapse a string
collapse = proc (s: string) returns (string)
out: array[char] := array[char]$[]
last: char := '\000'
for c: char in string$chars(s) do
if c ~= last then
last := c
array[char]$addh(out,c)
end
end
return (string$ac2s(out))
end collapse
 
% Show a string in brackets, with its length
brackets = proc (s: string)
stream$putl(stream$primary_output(),
int$unparse(string$size(s))
|| " <<<"
|| s
|| ">>>")
end brackets
 
% Show a string and its collapsed version, and the corresponding lengths
show = proc (s: string)
brackets(s)
brackets(collapse(s))
stream$putl(stream$primary_output(), "")
end show
 
% Try the examples from the task description
start_up = proc ()
examples: array[string] := array[string]$[
"",
"\"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 "
]
for ex: string in array[string]$elements(examples) do
show(ex)
end
end start_up</lang>
{{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|Cowgol}}==
2,114

edits