> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Reader Challenge: Write a Formula to Calculate Gift Totals in "The Twelve Days of Christmas"
- URL: https://nolongerset.com/challenge-calc-gift-count-by-day/
- Published: 2022-12-22T04:49:20.000Z
- Updated: 2026-05-08T12:52:46.000Z
- Description: How many total gifts does one's true love deliver by the nth day of Christmas? It's a deceptively tricky problem to solve.
- Author: Mike Wolfe
- Tags: Reader Challenge, #Import 2026-05-20 02:59

It's almost Christmas and my 10-year-old and 17-year-old both informed me that one's true love delivers 364 total gifts throughout the entirety of the song, "The Twelve Days of Christmas."

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2022/12/image-46.png)

My fifth-grade son thought this was interesting, but my high school senior-daughter wanted to come up with an algebraic formula that would take as input the song verse and produce as output the total number of gifts delivered to that point in the song. We both underestimated the challenge.

We set out to solve the problem without googling a solution. I'm sure many exist; it's the internet after all. Heck, there's probably an entire subreddit out there dedicated to just this one math problem. On the internet, even the niches have niches.

## Test-Driven Development

In keeping with my recent theme here, I started by creating a set of [doc tests](https://nolongerset.com/python-inspired-doc-tests-in-vba/). I used some simple Excel formulas to generate the solutions as shown above. Here are the twelve doc tests I started with:

```vba
'>>> GiftsByXmasDay(1)
' 1
'>>> GiftsByXmasDay(2)
' 4
'>>> GiftsByXmasDay(3)
' 10
'>>> GiftsByXmasDay(4)
' 20
'>>> GiftsByXmasDay(5)
' 35
'>>> GiftsByXmasDay(6)
' 56
'>>> GiftsByXmasDay(7)
' 84
'>>> GiftsByXmasDay(8)
' 120
'>>> GiftsByXmasDay(9)
' 165
'>>> GiftsByXmasDay(10)
' 220
'>>> GiftsByXmasDay(11)
' 286
'>>> GiftsByXmasDay(12)
' 364
Function GiftsByXmasDay(DayOfXmas As Long) As Long

    '--== Your code goes here ==--

End Function
```

## Reader Challenge

How would you solve this problem?

To verify your solution, start by grabbing my DocTests function [from here](https://nolongerset.com/python-inspired-doc-tests-in-vba/#sample-code). Then copy the above code comments and function definition and paste them into a blank code module. Run `DocTests` in the immediate window and confirm all 12 tests fail. Then fill in the function until all tests pass.

In the next couple of days, I will post at least two different solutions: one using a traditional function and another that uses recursion. 

Please refrain from posting your solutions in the comments of this article. Save them for one of the follow-up articles so that we don't have any spoilers here. Have fun!

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2022/12/image-44.png)

If the "12 Days of Christmas" song had a verse for every day of the year, your true love would need to deliver more than 8 million gifts. And leap years would require more than 67,000 additional gifts!

### Referenced articles

[Python-inspired Doc Tests in VBADoc tests are not a replacement for unit or integration testing. But they do provide the best return on investment (ROI) of any type of test, mostly because the effort to write them is near zero.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2020/09/20200921_173427---gbm18---.png)](https://nolongerset.com/python-inspired-doc-tests-in-vba/)

*Cover image created with [Microsoft Designer](https://designer.microsoft.com/)*