Destiny-land
It's..... The happiest blog on earth






Now, let's see....
(12 x 1) + (11 x 2) + (10 x 3) + (9 x 4) + (8 x 5) + (7 x 6) + (6 x 7) + (5 x 8) + (4 x 9) + (3 x 10) + (2 x 11) + (1 x 12)
Ah, but it turns out you receive the same number of pipers piping (12, on the last day) as you do partridges in pear trees (one per day, for all 12 days.) This holds true for the second and second-to-last day, so you can simplify the equation to...
2 x (12 + 22 + 30 + 36 + 40 + 42) = 2 x 182 = 364
I was a little disappointed I couldn't just say something like "twelve factorial" and let it go at that - say...
1! + 2! + 3! + 4! + 5!+ 6! + 7! + 8! + 9! + 10! + 11! + 12!
But the factorial symbol multiplies all the numbers counting up to the target number. You'd need to use the sum function.

 234
1+Σ+Σ+Σ...
d=1d=1d=1

Click here to see the complete equation.

We can use Perl to write a short program performing the same calcuations.

#!/usr/bin/perl

# In the song "The 12 Days of Christmas,"
# how many gifts, total, did my
# true love give to me?

for ($day=1; $day<=12; $day++)
{
  $newgifts = $day;
  $totalgifts += ($newgifts + $repeatgifts);
  $repeatgifts += $newgifts;
}

print "After 12 days of Christmas,"
print "my true love ";
print "had given me $totalgifts gifts \n";

OUTPUT:
After 12 days of Christmas, my true love had given me 364 gifts


Have a geeky holiday, everyone !!!

Click here for a longer script which breaks down the total by type of gift!
And by popular demand: the same script re-coded with a hash array!


6:24 AM



Sunday