From: Morton Goldberg Date: 2007-06-19T06:02:52+09:00 Subject: Re: Another Easy Beginner Question On Jun 18, 2007, at 1:19 PM, Matt Filizzi wrote: > Wouldn't it be this... > > gifts = 0 > (1..12).each do |x| > (1..x).each do { |y| gifts += y } ^^ > end > puts gifts Not quite. It should be: gifts = 0 (1..12).each do |x| (1..x).each { |y| gifts += y } end gifts # => 364 But this problem has a nice closed-form solution: def gifts(days) days * (days +1) * (days + 2) / 6 end gifts(12) # => 364 Regards, Morton