Python implementation of word wrap algorithm (as per Kunth)