in reply to
Re^2: arrange output in columns
in thread arrange output in columns
Thanks for the input. I knocked this up in part of my lunchbreak while munching a burrito, and it was totally untested. :-)
Update: I spotted the problems you mentioned before you posted and they've now been fixed.
Anyway, as my footer says, it's polite to ensure that the reader still has to think through some of the issues, especially as this may be a homework assignment! :-)
If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)