On Thu, 11 Dec 2008 21:44:31 -0500, Todd Benson wrote: >> data='0123456789abcdefghijklmnopqrstuvwxyz' >> list=data.split("") >> list.each do |i| >> list.each do |j| >> list.each do |k| >> list.each do |l| >> puts "#{i} #{j} #{k} #{l} " >> end >> end >> end >> end > > Logically equivalent on 1.8.7, but _don't_do_it_ (far too slow)... > > s = "0123456789abcdefghijklmnopqrstuvwxyz" > b = "" > (s * 4).split(//).combination(4) {|group| b << group.join << "\n"} Alternatively: STRING_LEN = 4 # length of each string to output BASE = 36 # number of symbols in data string (0..BASE ** STRING_LEN - 1).each do |i| puts i.to_s(BASE).rjust(STRING_LEN, '0') end Here this runs ~the same speed as the nested loops solution. This won't work for BASE > 36 however.