From: Todd Benson Date: 2008-12-12T11:44:31+09:00 Subject: Re: All possible letter combinations? On Thu, Dec 11, 2008 at 7:22 AM, DanDiebolt.exe wrote: >>... convert this script to ruby ... > > 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"} ...If just printing you could just use "p group.join", or "puts group". I find it interesting that it is about 5x slower than the code quoted above on my machine. I suppose it has to do with extra method calls inside the block, since it is almost on par if you don't do anything inside the block :-) Having b as an array without the join or "\n" basically halts my machine (10 seconds to recognize the ctrl-c interrupt). Todd