Tuesday, November 16, 2010

Lunchtime Scripting: Boustrophedonic text filter

Several ancient languages used a technique known as boustrophedonic writing, in which alternate lines of text ran in opposite directions.  Imagine English text in which every other line read right-to-left, instead of left-to-right.  It sounds odd--and looks bizarre at first--but studies have shown that most folks actually experience an increase in their reading speed with boustrophedonic text, once they "get used to it."  It's amazing how much speed one can gain when freed from the "reset to left margin, find next line, continue reading" overhead imposed by our writing style.

Want to try it out?  Sure you do!  If you happen to have a Unix system, here you go; just feed your text into this awk script...

awk '
   if (NF == 0) {
     NR--; print;
   } else if (NR %=2) {
   } else {
     for(x=NF;x != 0; x--) printf "%s ",$x ; printf "\n"
}' your-text-file

(Yes, I was bored...yes, I'm sure that Perl can do this in one line...)

Post a Comment