7
In this challenge, your input is a string of lower-case letters like this:
insertspacesbetweenwords
and a dictionary like the that from my other challenge. You may assume that the dictionary file contains only lower-case letters and line-feed characters. Furthermore, the last character in the dictionary file is a line-feed character and the entries are sorted alphabetically.
Write a function that given these two strings, returns a single string containing all possible ways to insert spaces between some of the characters in the input string, such that the words created are all in the dictionary. Each possibility shall be terminated with a line-feed character. Some lines of the output for the example are:
insert spaces between words
insert space s between words
insert spaces between word s
insert space s between word s
insert spaces be tween words
The order of the output lines doesn't matter.
This is codegolf, the usual scoring rules apply, standard loopholes are verboten.
Are trailing spaces acceptable? – Zgarb – 11 years ago
I still don't get the input format. Is it the string of letters and then each word in the dictionary? If so, how do we know when the input is done? – KSFT – 11 years ago
@KSFT Your input is two strings. One string contains the dictionary, the other contains the word-string where you shall insert spaces. – FUZxxl – 11 years ago
@Zgarb No. The question says “all possible ways to insert spaces between some of the characters in the input string;” trailing spaces are not between characters of the input string. – FUZxxl – 11 years ago
Is the word
sin your dictionary, but not other letters of the alphabet? – feersum – 11 years ago@feersum The example output is just a selection of the lines of the output for
insertspacesbetweenwords. The actual output is much longer. – FUZxxl – 11 years agosisn't a word I would expect to find in the dictionary, so it's still unclear to me whethersis a dictionary word, or if letters may be left over if they can't be included in any of the words. – feersum – 11 years ago@feersum In this particular example I used a dictionary where all single characters a re part of the dictionary. All words formed by inserting spaces between them must be in the dictionary as mentioned in the challenge. – FUZxxl – 11 years ago
Can the input string be empty? – Zgarb – 11 years ago
@Zgarb You may assume that it isn't. – FUZxxl – 11 years ago
@britishtea Please read the post, it says exactly how the dictionary string is formatted. It's one word per line, all lower-case characters, with a single line-feed character terminating each line. – FUZxxl – 11 years ago