From: Li Chen Date: 2009-07-24T11:47:31+09:00 Subject: Is recusion the best? Hi all, I have some codes implemented with recursion. When the loop/recursion number is small everything looks fine to me. But the program starts slow when the loop number is >7.I wonder if recursion is the best when the recursion number is >7? Thanks, Li #########################def table(array,word_size=1,word='') hash_table=Hash.new(0) # create the keys first array.each do |e| if word_size==1 hash_table["#{word+e}" ]=0 else hash_temp=table(array,word_size-1,word+e ) hash_table.merge!(hash_temp) end end # create the values based on keys hash_table.each do |k,v| hash_table[k]=k.tr('ACGT','0123').to_i(4) end return hash_table end ###################### array=['A','C','G','T'] #array=['A'] p table(array,10) -- Posted via http://www.ruby-forum.com/.