# 12 Days of Christmas Gift Totals

Ever wonder how many gifts were given by “My True Love”? Let’s figure it out.

• 1st day - 1 partridge
• 2nd day - 2 turtle doves and 1 partridge -> total 3 new items this day.
• Now the total is 1 + 3 = 4 -> (Day 1 plus Day 2)
• 3rd day - 3 french hens, 2 turtle doves and 1 partridge - 6 items
• New total is 4 + 6 = 10 items. Everything before this day gets repeated.

You can discover the grand total laboriously with a pen and paper, or you can write a formula: (This was written in php)

• Let \$n = number of days (12 days of Xmas and number of new gifts on the nth day)
• Let \$t = total gifts on previous day
• Let \$gt = grand total accumulated gifts.

Now go through the 12 days:

``````<?php
for (\$n = 1; \$n <= 12; \$n++) //count up from 1 to 12
{
\$gt += \$t;  // accumulate all the yesterdays plus today for a grand total.
echo "Day \$n Total = \$gt <br>";
}
?>
``````

Day 1 Total = 1
Day 2 Total = 4
Day 3 Total = 10
Day 4 Total = 20
Day 5 Total = 35
Day 6 Total = 56
Day 7 Total = 84
Day 8 Total = 120
Day 9 Total = 165
Day 10 Total = 220
Day 11 Total = 286
Day 12 Total = 364

Change \$n to test other scenarios, such as n = 30 One month. Wow! If “True Love carried on for a month, the total would be 4960 gifts! and the song would be really irritating!”

Categories:

Updated: