From: "Kroeger, Simon (ext)" Date: 2005-12-05T22:02:41+09:00 Subject: Re: [QUIZ] Weird Numbers (#57) Solution Hi, I aimed for a fast yet elegant solution: (Its way faster than my first try, way slower than my fastest, but the one I liked the most) --------------------------------------------------------- require 'set' class Fixnum def weird? divisors = (1..1+self/2).select{|i| (self % i).zero?} return false if divisors.inject{|s, x| s + x} <= self !divisors.inject([0].to_set) do |sums, d| sums.merge(sums.map{|s| s + d}) end.include?(self) end end $stdout.sync = true 1.upto((ARGV.shift || 1000).to_i){|i| puts i if i.weird?} --------------------------------------------------------- cheers Simon