> > Your task is to write a bit of Ruby code that will find and report all > integers that are divisible by their reverse. For example, 9801 is > divisible by 1089. > > Now *I think* the patterns are complete so it is a complete solution. Let me know if you notice some numbers are missing. ####### def revs(res,ul=1000000) res.select{|x| x % x.to_s.reverse.to_i == 0 and x.to_s != x.to_s.reverse and x < ul.to_i}.uniq.sort end ulim = (ARGV[0] or 1_000_000).to_i res = [] arr = [[{"0"=>"_","1"=>"9","2"=>"12","3"=>"87","4"=>"0"},"87","12"], [{"0"=>"_","1"=>"9","2"=>"01","3"=>"98","4"=>"0"},"98","01"]] t = Time.now arr.each do |q| (0..5**((ulim-1).to_s.length - 4)-1).each do |x| str = x.to_s(5).rjust((ulim-1).to_s.length - 4,"0").split(//).map{|x| q[0][x]}.join res << (q[1] + str + q[2]).to_i end end outs = revs(res,ulim) puts outs puts puts "#{Time.now - t} seconds" ############### ruby quiz161.rb 8712 9801 87912 98901 879912 989901 0.001758 seconds ruby quiz161.rb 1_000_000_000 8712 9801 87912 98901 879912 989901 8799912 9899901 87128712 87999912 98019801 98999901 871208712 879999912 980109801 989999901 0.235533 seconds Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/ruby/list.html