the twelve days of christmas?

HarryA

Jan 22, 2017
90
Joined
Jan 22, 2017
Messages
90
Greetings from Penn's woods.

How would you calculate the number of gifts in the song "The Twelve Days of Christmas" ?

I would think it is the sum of gifts+days as gifts goes from 1 to 12 and as days goes from 12 to 1.
That is as far as i can get. You do not get any credit unless you show your work ;)
 

Alec_t

Jul 7, 2015
3,817
Joined
Jul 7, 2015
Messages
3,817
Sum of n numbers 1 to n = n*(n+1)/2.
n=12, therefore sum = 12*13/2 = 78.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
I was thinking 13*6, but your explanation is better than I would have given.
 

HarryA

Jan 22, 2017
90
Joined
Jan 22, 2017
Messages
90
Yes but you did not show how to calculate it - so no credit.
I was wrong it is not the sum of gifts and days but the product:
sum = sum + (gifts++ * days-- )

day gifts days
1 1 12 = 12
2 2 11 = 22
3 3 10 = 30 and so on but what is the mathematical expression?
 

HarryA

Jan 22, 2017
90
Joined
Jan 22, 2017
Messages
90
that works:

Private Sub Command2_Click()
Dim gifts As Integer
Dim sum As Integer

For gifts = 1 To 12 Step 1
sum = sum + (gifts * (gifts + 1)) / 2
Next gifts

Text2.Text = Str(sum) 'sum = 364
End Sub
 

HarryA

Jan 22, 2017
90
Joined
Jan 22, 2017
Messages
90
in this one it is easier to see the gifts go up and the days go down.
Private Sub Command1_Click()
Dim days As Integer
Dim gifts As Integer
Dim sum As Integer
days = 12
For gifts = 1 To 12 Step 1
sum = sum + gifts * days
days = days - 1
Next gifts
Text1.Text = Str(sum)
End Sub
 
Top