Jump to content

Determine if a string is collapsible: Difference between revisions

Add Miranda
(add sed)
(Add Miranda)
Line 2,210:
ans = ║ - Hary S Truman ║
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>
 
2,114

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.