Longest substrings without repeating characters: Difference between revisions

Add Factor
(Added 11l)
(Add Factor)
Line 181:
Longest substring with no repeats found in 'unixdict.txt': ['mbowel
disgrunt']
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<lang factor>USING: formatting grouping io kernel math sequences sets ;
 
: unique-substrings ( seq n -- newseq )
tuck <clumps> [ cardinality = ] with filter ;
 
: longest-unique-substring ( seq -- newseq )
dup length { } [ 2dup empty? swap 0 > and ]
[ drop 2dup unique-substrings [ 1 - ] dip ] while
2nip [ "" like ] map members ;
 
: test ( seq -- )
dup longest-unique-substring "%u -> %u\n" printf ;
 
"Longest substrings without repeating characters:" print
{ "xyzyabcybdfd" "xyzyab" "zzzzz" "a" "" } [ test ] each</lang>
{{out}}
<pre>
Longest substrings without repeating characters:
"xyzyabcybdfd" -> { "zyabc" "cybdf" }
"xyzyab" -> { "zyab" }
"zzzzz" -> { "z" }
"a" -> { "a" }
"" -> { }
</pre>
 
1,808

edits