Longest substrings without repeating characters: Difference between revisions

Content added Content deleted
(added Arturo)
(Add Miranda)
Line 803: Line 803:
</pre>
</pre>


=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [ Stdout (show test ++ " -> " ++ show (lswrc test) ++ "\n")
| test <- tests]

tests :: [[char]]
tests = ["xyzyabcybdfd", "xyzyab", "zzz", "a"]

lswrc :: [*]->[[*]]
lswrc s = nub [s' | s'<-noreps; #s' = maxlen]
where maxlen = max (map (#) noreps)
noreps = [norep (drop n s) | n<-[0..#s-1]]
norep = reverse . norep' []
norep' mem [] = mem
norep' mem (a:as) = mem, if a $in mem
= norep' (a:mem) as, otherwise

in :: *->[*]->bool
in item [] = False
in item (a:as) = a = item \/ item $in as

nub :: [*]->[*]
nub = reverse . nub' []
where nub' mem [] = mem
nub' mem (a:as) = nub' mem as, if a $in mem
= nub' (a:mem) as, otherwise</syntaxhighlight>
{{out}}
<pre>"xyzyabcybdfd" -> ["zyabc","cybdf"]
"xyzyab" -> ["zyab"]
"zzz" -> ["z"]
"a" -> ["a"]</pre>
=={{header|Modula-2}}==
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE LSWRC;
<syntaxhighlight lang="modula2">MODULE LSWRC;