From: Glen Holcomb Date: 2008-10-18T07:09:35+09:00 Subject: Re: Counting ------=_Part_10625_25830134.1224281415876 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Fri, Oct 17, 2008 at 4:07 PM, Craig Demyanovich wrote: > Here's one way: > > multiples = [] > (1..1000).each do |number| > if (number % 2) == 0 && (number % 6) == 0 > multiples << number > end > end > puts "multiples of 2 and 6 between 1 and 1000: #{multiples.join(', ')}" > print "sum of multiples: " > puts multiples.inject(0) { |sum, multiple| sum + multiple } > > Regards, > Craig > You should be able to ignore the % 2 bit as if it's divisible by 6 then it's divisible by 2 -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_10625_25830134.1224281415876--