Monday, December 29, 2008

Twelve Days of Christmas

The formula for the quantity of a given item on a given day of Christmas is:

N * (D-N+1), where N<=D

N is the number of that item given per day; for instance, 5 golden rings are given each day on or after day 5. D is which day it is: the fifth day of Christmas. N is less than or equal to D, otherwise you get negative number results.

I guess I could write a formula for how many total items of everything that you have on each day, regardless of what the items are. You have four total objects on the second day: two partridges and two turtle doves. But I don't feel like figuring out that formula.

I also thought of writing a C++ program that would display a list of all the items you have on any day... but it's been a really long time since I wrote any C++ programs and it would take too long to figure out all the details that I've forgotten. I vaguely know how I would do it. I'd probably use some kind of ... I don't even remember the name of it now. A set, or whatever the variable is that has several different custom-made attributes that can be displayed as text. An "object" or whatever. If I didn't do that, I guess I could make a whole bunch of IF-THEN statements, which would be hilarious and horrible. But I'm not going to.

How many French Hens do you have on the fourth day of Christmas?

N=3 hens per day
D=4th day of Christmas

N * (D-N+1)
3 * (4-3+1)
3 * 2
= 6 French Hens

Now you know. This is just in case a situation ever comes up where you have to find out how many Swans A-Swimming or Lords A-Leaping you got this year.

No comments: