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 – 2015-02-08T15:41:20.653
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 – 2015-02-08T15:42:50.070
@KSFT Your input is two strings. One string contains the dictionary, the other contains the word-string where you shall insert spaces. – FUZxxl – 2015-02-08T15:51:09.743
@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 – 2015-02-08T15:54:38.707
Is the word
s
in your dictionary, but not other letters of the alphabet? – feersum – 2015-02-10T07:13:32.580@feersum The example output is just a selection of the lines of the output for
insertspacesbetweenwords
. The actual output is much longer. – FUZxxl – 2015-02-10T07:17:29.763s
isn't a word I would expect to find in the dictionary, so it's still unclear to me whethers
is a dictionary word, or if letters may be left over if they can't be included in any of the words. – feersum – 2015-02-10T07:21:35.500@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 – 2015-02-10T07:26:43.673
Can the input string be empty? – Zgarb – 2015-02-10T12:05:50.567
@Zgarb You may assume that it isn't. – FUZxxl – 2015-02-10T12:33:39.883
@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 – 2015-02-10T13:00:59.900