It's the sort of thing I used to give as an exercise to students.
Wish I'd been in your class.
Explicit looping looks so strenuous.
I know: I kept thinking "map ... join": too much perl.
To make the tr|pr method more general, you can count columns first
with
But that's multi-pass:-).
You could of course, use one pass of wc to count the words and lines,
then divide words by lines to get cols:-).
There are too many mad genius coders on this list.
Next: count the number of angels dancing on the head of a pin using an
acid function.
Can we talk about plan9 now, please?
D