Every way to split into words
Write all_breaks(text, words) that returns every way to split text into a sequence of
words from words (reusable), each as a space-separated sentence. Order of the output
does not matter.
all_breaks("catsanddog", ["cat", "cats", "and", "sand", "dog"]) -> ["cats and dog", "cat sand dog"]
all_breaks("pineapplepenapple", ["apple", "pen", "applepen", "pine", "pineapple"])
-> ["pine apple pen apple", "pineapple pen apple", "pine applepen apple"]
all_breaks("catsandog", ["cats", "dog", "sand", "and", "cat"]) -> []
Backtracking over prefixes, with memoisation of "all sentences for the suffix starting at
i" so that shared suffixes are not re-explored.
def all_breaks(text, words):
...