Word break problem: Difference between revisions

Content added Content deleted
(→‎Functional Python: Pylinted for Python 3, added a {Works with} tag.)
(Added Seed7 example)
Line 1,203: Line 1,203:


}</lang>
}</lang>

=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";

const func boolean: wordBreak (in string: stri, in array string: words, in string: resultList) is func
result
var boolean: found is FALSE;
local
var string: word is "";
begin
if stri = "" then
writeln(resultList);
found := TRUE;
else
for word range words do
if startsWith(stri, word) and
wordBreak(stri[succ(length(word)) ..], words, resultList & " " & word) then
found := TRUE;
end if;
end for;
end if;
end func;

const proc: main is func
local
const array string: words is [] ("a", "bc", "abc", "cd", "b");
var string: stri is "";
var string: resultList is "";
begin
for stri range [] ("abcd", "abbc", "abcbcd", "acdbc", "abcdd") do
write(stri <& ": ");
if not wordBreak(stri, words, resultList) then
writeln("can't break");
end if;
end for;
end func;</lang>

{{out}}
<pre>
abcd: a b cd
abbc: a b bc
abcbcd: a bc b cd
abc b cd
acdbc: a cd bc
abcdd: can't break
</pre>


=={{header|Sidef}}==
=={{header|Sidef}}==