#!ruby -na d=$F.map &:to_i $m=[] $l=[8,11,13][$$%3] def f s,a,b \x09if s > 0 && b.size < $l \x09\x09a.size.times{|i|f(s-a[i],a[i,$$],b+[a[i]])} \x09elsif s == 0 \x09\x09$m<<b \x09end end f(d.shift,d,[]) k=$m.sort_by{|i|i.size}[0] puts k ? k*" ":"-"
Note that non-ascii characters in the above source code will be escaped (such as \x9f).