Trabb Pardo-Knuth algorithm in ruby