4 kyu
Paragraph Setting: Align Left
92 of 98discotechne
Description:
Write a code that takes some text (argument 1) and processes it into a paragraph one line at a time. The lines should break as near as possible to the maximum line length (argument 2), breaking words if needed and inserting a hyphen to indicate where a word has been broken.
Follow these rules:
- Spaces and punctuation, including inserted hyphens, should be included in line length.
- There should be no spaces at the start or end of a line. Any such spaces should be removed and so not included in line length.
- Any punctuation adjoining the start or end of a word should not be detached from the word by a line break.
- Any added hyphens must be at least two alphanumeric characters from both the start and the end of the word being broken (or from the nearest hyphen, for words that are already hyphenated). If this is not possible, the line should instead be broken either
- at the previous white space, or
- if the word is already hyphenated and the hyphen lies before the maximum line length, after that hyphen (but not before such hyphens).
For the purpose of this exercise, it can be assumed that:
- the maximum line length will never be less than 15 characters;
- any input text will be standard prose throughout, and will not contain any accented characters ( e.g.
é
); - any input text will use spaced en-dashes for parenthesis, rather than non-spaced em-dashes (see http://www.dashhyphen.com/en-dash/);
- there will be no long stretches of non-alphanumeric characters in the input text (although quotation marks, including for nested quotations, should be accounted for), and no multiple spaces;
"
and "'" serve as quotation marks. - underscores are included in alphanumeric characters.
Algorithms
Similar Kata:
Stats:
Created | Jun 11, 2017 |
Published | Jun 11, 2017 |
Warriors Trained | 611 |
Total Skips | 8 |
Total Code Submissions | 1571 |
Total Times Completed | 98 |
JavaScript Completions | 92 |
Python Completions | 9 |
Total Stars | 17 |
% of votes with a positive feedback rating | 85% of 20 |
Total "Very Satisfied" Votes | 16 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 3 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 5 kyu |