Word break problem: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: 'strict' compatible) |
(Added Sidef) |
||
Line 1,173: | Line 1,173: | ||
}</lang> |
}</lang> |
||
=={{header|Sidef}}== |
|||
{{trans|zkl}} |
|||
<lang ruby>func word_break (str, words) { |
|||
var r = ->(str, arr=[]) { |
|||
return true if str.is_empty |
|||
for word in (words) { |
|||
str.begins_with(word) || next |
|||
if (__FUNC__(str.substr(word.len), arr)) { |
|||
arr << word |
|||
return arr |
|||
} |
|||
} |
|||
return false |
|||
}(str) |
|||
r.kind_of(Array) ? r.reverse : nil |
|||
} |
|||
var words = %w(a o is pi ion par per sip miss able) |
|||
var strs = %w(a amiss parable opera operable inoperable permission mississippi) |
|||
for str in (strs) { |
|||
printf("%11s: %s\n", str, word_break(str, words) \\ '(not possible)') |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
a: ["a"] |
|||
amiss: ["a", "miss"] |
|||
parable: ["par", "able"] |
|||
opera: ["o", "per", "a"] |
|||
operable: ["o", "per", "able"] |
|||
inoperable: (not possible) |
|||
permission: ["per", "miss", "ion"] |
|||
mississippi: ["miss", "is", "sip", "pi"] |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |