On 6/18/07, danielj <danielj / sleepingindian.org> wrote:
>
> 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?
> <strong>(Hint: You will need a loop inside another). </strong>
>
> 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 <em>loop inside a loop</
> em>?


Note that your program does not solve the problem (which is easy to
misinterpret). To clarify the problem:

On day 1, you get 1 gift.
On day 2, you get 3 gifts, not two (two doves AND one bird/tree combo).
On day 3, you get 6 gifts - 3 hens, 2 doves, one more pear tree
w/attendant partridge.
and so on... until
On day 11 you get 66 gifts, and
On day 12 you get 78 gifts.


Do you see how a loop within a loop may be helpful?

Good luck!

-A