r/dailyprogrammer_ideas • • Jan 07 '19

[intermediate] Scriptio continua

Description --Use a dictionary to put spaces between the words in a piece of Scriptio continua--

Input description --A string with no spaces--

itdidsoindeedandmuchsoonerthanshehadexpectedbeforeshehaddrunkhalfthebottleshefoundherheadpressingagainsttheceilingandhadtostooptosaveherneckfrombeingbrokenshehastilyputdownthebottlesayingtoherselfthatsquiteenoughihopeishallnotgrowanymoreasitisicantgetoutatthedooridowishihadnotdrunkquitesomuch

Output description --A string with spaces between words--

it did so indeed and much sooner than she had expected before she had drunk half the bottle she found her head pressing against the ceiling and had to stoop to save her neck from being broken she hastily put down the bottle saying to herself thats quite enough i hope i shall not grow any more as it is i cant get out at the door i do wish i had not drunk quite so much

Notes/Hints --A trie can be used to implement this efficiently--

5 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/Philboyd_Studge Jan 21 '19

Even in the very beginning of the input code - you could have indeed or in deed both would be valid, although one does not make sense in context. Finding sense in context would be wayyy NP hard.

1

u/tomekanco Jan 23 '19

A simple greedy heuristic will give a good result, for example choosing the longest whenever possible. Human communication is not NP, we do it routinely :p

Perfect understanding on the other hand ☆゚.*・。゚