10
1
Given this text
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
write the shortest program that produces the same text justified at 80 character. The above text must look exactly as:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
Rules:
- words must not be cut
- extra spaces must be added
- after a dot.
- after a comma
- after the shortest word (from left to right)
- the result must not have more than 2 consecutive spaces
- last line is not justified.
- lines must not begin with comma or dot.
- provide the output of your program
winner: The shortest program.
note: The input string is provided on STDIN as one line (no line feed or carriage return)
update:
The input string can be any text with word length reasonnable (ie. not more than 20~25 char) such as:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede pellentesque fermentum. Maecenas adipiscing ante non diam sodales hendrerit. Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. Curabitur aliquet pellentesque diam. Integer quis metus vitae elit lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum posuere, metus purus iaculis lectus, et tristique ligula justo vitae magna. Aliquam convallis sollicitudin purus. Praesent aliquam, enim at fermentum mollis, ligula massa adipiscing nisl, ac euismod nibh nisl eu lectus. Fusce vulputate sem at sapien. Vivamus leo. Aliquam euismod libero eu enim. Nulla nec felis sed leo placerat imperdiet. Aenean suscipit nulla in justo. Suspendisse cursus rutrum augue. Nulla tincidunt tincidunt mi. Curabitur iaculis, lorem vel rhoncus faucibus, felis magna fermentum augue, et ultricies lacus lorem varius purus. Curabitur eu amet.
3Why ask people to provide the output of their program? Are you that worried about people failing to check their results before posting? – Peter Taylor – 2011-12-10T14:05:31.317
1I'm tempted to provide a php program which consists of the output text. ;-) Seriously though, the spaces on the second line of the output text seem to have been added to the spaces at random? Is there some pattern to it that I'm not seeing, and if not, how can we be expected to produce exactly that output for the given input? – Gareth – 2011-12-10T14:23:34.543
@Gareth: Sorry, my bad. I made a mistake, is after the comma, not after incididunt. Question edited. – Toto – 2011-12-10T15:36:46.717
@Peter Taylor: Just because I'm not able to test all languages. – Toto – 2011-12-10T15:38:29.117
Does the program have to work also for inputs other than that one paragraph of Lipsum? – Ilmari Karonen – 2011-12-10T17:03:12.150
1@Ilmari Karonen: Yes, the input string can be anything. – Toto – 2011-12-10T17:06:52.587
Just after submitting my answer I saw that you changed the task by removing the restriction to the input string. Can you please adjust the question itself. I'll then try to rewrite my answer to work for any input. – Howard – 2011-12-10T17:32:46.103
What should the program do if the text cannot be justified within the rules given above (e.g. one word with more than 80 charcters or two words with 50 each, ...)? – Howard – 2011-12-10T17:35:41.430
@Howard: see my update – Toto – 2011-12-10T18:14:28.793
Thank you for clarifying. But consider also a text with e.g. 4 words with 20 caracters each. You cannot justify it according to your rules. – Howard – 2011-12-10T18:38:40.837