Skip to main content
1 of 3
xnor
  • 149.7k
  • 3
  • 94
  • 133

Underfull \hbox (badness 10000)

Every TeX user has been warned many times of their terribly underfull or overfull hbox's. This challenge is to rate how badly underfull or overfull a line of text is with a simplified line wrapper.

Task

You are given space-separated string or list of words consist of letters a-zA-z. Output the minimal badness that can be achieved for the first line.

You need to wrap text on a line that's 10 characters wide. The text can only be split on spaces, no in the middle of words. Any letter that spill beyond the width count for 1000 overfull badness each, and any leftover empty space at the end of the line counts for 1000 underfull badness. Output the smallest badness number possible.

Examples

For input Overfull hbox, we put the word "hbox" in the first line for 3000 overfull badness, or wrap it to the second line for 2000 underfull badness which is smaller, so the output is 2000.

0123456789 Overfull hbox ^^^ Overfull hbox ^^ 

Note that we don't care about badness of the second line.

For input Supercalifragilisticexpialidocious, we can't do anything put in on one line, for badness 24000 (overfull).

Test cases

TODO


Sandbox: Is it OK to have a multiplier of 1000 for theme? Should the underfull and overfull badness penalties be different, like 1000 vs 2000?

xnor
  • 149.7k
  • 3
  • 94
  • 133