Determine if a string is collapsible: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) m (Move PL/M to the right spot (oops)) |
Not a robot (talk | contribs) (Add BCPL) |
||
Line 509: | Line 509: | ||
</pre> |
</pre> |
||
=={{header|BCPL}}== |
|||
<lang bcpl>get "libhdr" |
|||
// Collapse a string |
|||
let collapse(in, out) = valof |
|||
$( let o = 0 |
|||
for i = 1 to in%0 |
|||
unless i>1 & in%i = in%(i-1) |
|||
$( o := o + 1 |
|||
out%o := in%i |
|||
$) |
|||
out%0 := o |
|||
resultis out |
|||
$) |
|||
// Print string with brackets and length |
|||
let brackets(s) be |
|||
writef("%N: <<<%S>>>*N", s%0, s) |
|||
// Print original and collapsed version |
|||
let show(s) be |
|||
$( let v = vec 1+255/BYTESPERWORD |
|||
brackets(s) |
|||
brackets(collapse(s, v)) |
|||
wrch('*N') |
|||
$) |
|||
let start() be |
|||
$( show("") |
|||
show("*"If I were two-faced, would I be wearing this one?*" --- Abraham Lincoln ") |
|||
show("..1111111111111111111111111111111111111111111111111111111111111111111788") |
|||
show("I never give 'em hell, I just tell the truth, and they think it's hell. ") |
|||
show(" --- Harry S Truman ") |
|||
$)</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: <<<..1111111111111111111111111111111111111111111111111111111111111111111788>>> |
|||
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|Bracmat}}== |
=={{header|Bracmat}}== |
||
<lang Bracmat> ( colapse |
<lang Bracmat> ( colapse |