gets.chars{|c|f=->a=$*.pop{Z=c>?-?a:a.transpose} $*<<f[c[/\D/]?(r=f[] l=f[]+r)[99]?[[c]*Z]*r :l.map{|x|(x+[?.]*41)[0,l.map(&:size).max]}:c.hex]} puts Z.map &:join
Note that non-ascii characters in the above source code will be escaped (such as \x9f).