#!/local/bin/ruby all = (1..16).to_a all.combination(4){ |a1| next if a1[0]+a1[1]+a1[2]+a1[3] != 34 (all - a1).combination(4){ |a2| next if a2[0]+a2[1]+a2[2]+a2[3] != 34 (all - a1 - a2).combination(4){ |a3| next if a3[0]+a3[1]+a3[2]+a3[3] != 34 a4 = all - a1 - a2 - a3 a1.permutation { |b1| a2.permutation { |b2| a3.permutation { |b3| a4.permutation { |b4| next if b1[0]+b2[0]+b3[0]+b4[0] != 34 next if b1[1]+b2[1]+b3[1]+b4[1] != 34 next if b1[2]+b2[2]+b3[2]+b4[2] != 34 puts b1.join(' ') puts b2.join(' ') puts b3.join(' ') puts b4.join(' ') puts "---------------" } } } } } } }