From: James Edward Gray II Date: 2005-12-13T03:44:00+09:00 Subject: Re: Calculating single-digit summands On Dec 12, 2005, at 11:02 AM, draq wrote: > This is a newer algorithm which works much more faster. > > def sum (arr) > # sorry James Edward Gray II, but I'm not using an enum. You don't think so? Let's ask Ruby... >> Array.ancestors.find { |par| par.to_s =~ /enum/i } => Enumerable >> arr = Array.new => [] >> arr.is_a? Enumerable => true >> arr.respond_to? :inject => true Ruby thinks so. Let's try a sum: >> arr = (1..10).to_a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >> arr.inject { |sum, n| sum + n } => 55 Looks good to me. > arri.each do |a| > arri.delete_if { |a| sum(a) != number } > end The whole point of delete_if() is that you don't need the each(). Try taking it out. ;) James Edward Gray II