Jaypee wrote:

> Example: Imagine you had to emulate an old time text processor to
> justify lines to a given width, by adding spaces where there are already.
> The width is w

w=60

DATA.each_line {|line|

  t=line.split;n=t.size-1;q,r=(w-t.join.size).divmod(n)
  print t.zip([" "*q]*n,[" "]*r);puts""

}

print "="*w

__END__
The quick red fox jumps over the lazy brown hogs.
The quick red fox jumps over lazy brown hogs.
The quick red fox jumps over lazy hogs.
The quick fox jumps over lazy hogs.
The quick fox.


-----
The output is

The   quick   red  fox  jumps  over  the  lazy  brown  hogs.
The   quick   red   fox   jumps   over   lazy   brown  hogs.
The    quick    red    fox    jumps    over    lazy    hogs.
The      quick     fox     jumps     over     lazy     hogs.
The                        quick                        fox.
============================================================