"Go with the flow" .Net Code execution

Job ID: 34271811

Budget: $10 – $30 CAD

In typesetting, a “river” is a string of spaces formed by gaps between words that extends down
several lines of text. For instance, Figure F.1 shows several examples of rivers highlighted in red
(text is intentionally blurred to make the rivers more visible).
Figure F.1: Examples of rivers in typeset text.
Celebrated river authority Flo Ng wants her new book on rivers of the world to include the
longest typographic rivers possible. She plans to set the text in a mono-spaced font (all letters
and spaces have equal width) in a left-aligned column of some fixed width, with exactly one
space separating words on each line (the text is not aligned on the right). For Flo, a “river” is
defined as a sequence of spaces lying in consecutive lines in which the position of each space in
the sequence (except the first) differs by at most 1 from the position of the space in the line
above it. Trailing white space cannot appear in a river. Words must be packed as tightly as
possible on lines; no words may be split across lines. The line width used must be at least as long
as the longest word in the text. For instance, Figure F.2 shows the same text set with two
different line widths.
Line width 14 / River of length 4
The Yangtze is|
the third |
longest river |
in*Asia and |
the*longest in|
the*world to |
flow*entirely |
in one country|
Line width 15 / River of length 5
The Yangtze is |
the third |
longest*river |
in Asia*and the|
longest*in the |
world to*flow |
entirely*in one|
country |
Figure F.2: Longest rivers (*) for two different line widths.
Given a text, you have been tasked with determining the line width that produces the longest
river of spaces for that text.
Related categories: .NET C# Programming WPF