From: Matt Filizzi Date: 2007-06-19T02:19:35+09:00 Subject: Re: Another Easy Beginner Question ------=_Part_45174_21631811.1182187176422 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Wouldn't it be this... gifts = 0 (1..12).each do |x| (1..x).each do { |y| gifts += y } end puts gifts Note the difference between mine and yours, where I count each item instead of each set. So 5 gold rings counts as 5 instead of 1. I think it all depends on how the original question was intended. On 6/18/07, Sammy Larbi wrote: > > I'm not sure why you'd want to, but I suppose you could do something like: > > gifts=0 > (1..12).each do |i| > (1..i).each { |j| gifts += 1 } > end > puts gifts > > danielj wrote, On 6/18/2007 11:50 AM: > > There is a song that goes like this: > > > > On the first day of Christmas, my true love sent to me a partridge > > in a pear tree. > > On the second day of Christmas, my true love sent to me two turtle > > doves and a partridge in a pear tree. > > ... > > > > If this goes on for the 12 days of Christmas. How many presents will > > your true love send you over Christmas? > > (Hint: You will need a loop inside another). > > > > I don't think you need a loop inside a loop.... Here is what I did: > > > > day = 0 > > gifts = 0 > > > > 12.times do > > day = day + 1 > > gifts = gifts + day > > end > > > > print gifts > > > > Does anyone know how you would do it with a loop inside a loop > em>? > > > > > > > > > > > > > ------=_Part_45174_21631811.1182187176422--