Given:
- A phrase with the spaces removed and converted to lower case - e.g. "ashotinthearm" from "a shot in the arm";
- A dictionary which returns true or false if a word exists ("a", "as", "ash", "shot", "hot", etc., would all return true)
What is an efficient method to find the individual words which, when glued together with spaces, make up that phrase?
There may be more than one solution, even if some are gibberish:
- ashotinthearm (a shot in the arm, as hot in the arm)
- asintended (as intended, as in tended)
- brothersinlaw (brothers in law, brother sin law)
- guysanddolls (guys and dolls, guy sand dolls)
- haveascrewloose (have a screw loose, have as crew loose)
- ifeelthepinch (I feel the pinch, if eel the pinch)
- isinyourcourt (is in your court, I sin your court)
- manorhouse (manor house, man or house)
- manormouse (man or mouse, manor mouse)
- newzealand (New Zealand, new zeal and)
- oneatatime (one at a time, on eat a time)
- portableradio (portable radio, port able radio)
- scotspine (scots pine, scot spine)
- shopsoiled (shop soiled, shops oiled)
Would ideally prefer a PERL and/or regex solution, but grateful for any suggestions.