Word break problem: Difference between revisions

Content deleted Content added
Added Seed7 example
Line 182: Line 182:
abcdd:
abcdd:
Not parseable with these words</pre>
Not parseable with these words</pre>

=={{header|J}}==
With such short sentences we can find the partition sets, then chech that all are words.

<lang J>
Filter=: (#~`)(`:6)
all_partitions=: <@(<;.1)"1 _~ (1,.[:#:[:i.2^<:@:#) NB. all_partitions 'abcd'

WordBreak=: adverb def '(; ([: ;:inv L:_1 [: (0=[:#-.&m)&>Filter all_partitions))&>@boxopen'
</lang>

<pre>
[dictionary=: ;: 'a bc abc cd b'
┌─┬──┬───┬──┬─┐
│a│bc│abc│cd│b│
└─┴──┴───┴──┴─┘


]sentences =: ;: 'abcd abbc abcbcd acdbc abcdd'
┌────┬────┬──────┬─────┬─────┐
│abcd│abbc│abcbcd│acdbc│abcdd│
└────┴────┴──────┴─────┴─────┘

dictionary WordBreak sentences
┌──────┬────────┬─────────┐
│abcd │a b cd │ │
├──────┼────────┼─────────┤
│abbc │a b bc │ │
├──────┼────────┼─────────┤
│abcbcd│abc b cd│a bc b cd│
├──────┼────────┼─────────┤
│acdbc │a cd bc │ │
├──────┼────────┼─────────┤
│abcdd │ │ │
└──────┴────────┴─────────┘
</pre>


=={{header|Javascript}}==
=={{header|Javascript}}==