From: Gavin Kistner Date: 2005-11-28T05:22:41+09:00 Subject: Re: recursion On Nov 25, 2005, at 3:52 PM, mathew wrote: > cyberco wrote: >> I'm trying to print every combination of three characters from the >> range (a..z). I thought recursion would be the most elegant solution, >> but that got me quite confused :) Any suggestions? > > Definitely not recursion. Consider that your problem is equivalent > to printing every possible 3 digit number in base 26 :-) Which leads to this alternative solution: ( 'aaa'.to_i(36)..'zzz'.to_i(36) ).map{ |i| (str=i.to_s(36)) =~ /^[a- z]{3}$/ && str }.compact Far less elegant than 'aaa'..'zzz', but there you have it. :)