Determine if a string is collapsible: Difference between revisions
Content added Content deleted
(add sed) |
Not a robot (talk | contribs) (Add Miranda) |
||
Line 2,210: | Line 2,210: | ||
ans = ║ - Hary S Truman ║ |
ans = ║ - Hary S Truman ║ |
||
PASSES 1 out of 1 test |
PASSES 1 out of 1 test |
||
</pre> |
|||
=={{header|Miranda}}== |
|||
<syntaxhighlight lang="miranda">main :: [sys_message] |
|||
main = [Stdout (lay (map test tests))] |
|||
tests :: [[char]] |
|||
tests |
|||
= [ |
|||
"", |
|||
"\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", |
|||
"..1111111111111111111111111111111111111111111111111111111111111111111788", |
|||
"I never give 'em hell, I just tell the truth, and they think it's hell. ", |
|||
" --- Harry S Truman " |
|||
] |
|||
test :: [char]->[char] |
|||
test s = lay [before, after] |
|||
where before = disp s |
|||
after = disp (collapse s) |
|||
disp :: [char]->[char] |
|||
disp s = show (#s) ++ ": <<<" ++ s ++ ">>>" |
|||
collapse :: [*]->[*] |
|||
collapse [] = [] |
|||
collapse [x] = [x] |
|||
collapse (x:y:xs) = collapse (y:xs), if x=y |
|||
= x:collapse (y:xs), otherwise</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: <<<..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> |
</pre> |
||