Houses of cards and triangular numbers
October 26, 2024 at 2:52 PM by Dr. Drang
November’s issue of Scientific American has a fun little puzzle about houses of cards. I solved it one way and SciAm solved it another, so I thought it worth a quick post.
The houses of cards are arranged in triangular shapes, like this:
This is an end view. SciAm has a nice 3D drawing of the houses, which you may want to look at. If you have an Apple News subscription, SciAm is one of the magazines that comes with it.
I’m showing the tilted “wall” cards in blue and the flat “floor” cards in red to help us with the calculations. The number under each house is the total number of cards needed to build that house. The question is this: Can you build a house like this with 100 cards, and if so, how many stories will it be?
Let’s start by figuring out how many cards of each type there are. Here’s a table for the houses shown above:
Stories | Wall cards | Floor cards | Total cards |
---|---|---|---|
1 | 2 | 0 | 2 |
2 | 6 | 1 | 7 |
3 | 12 | 3 | 15 |
4 | 20 | 6 | 26 |
The number of wall cards go in this sequence:
2
2 + 4
2 + 4 + 6
2 + 4 + 6 + 8
which we can rewrite as
2 (1)
2 (1 + 2)
2 (1 + 2 + 3)
2 (1 + 2 + 3 + 4)
The sums in parentheses form a familiar sequence. They are the trianglar numbers: 1, 3, 6, 10, … I always think of these as Gauss’s numbers because of the (perhaps apocryphal) story of how, as a schoolboy, he figured out how to quickly get the sum of the first hundred natural numbers without actually doing the summation. The sum of the first numbers is the triangular number
So the number of wall cards for an -story house is twice the associated triangular number
The number of floor cards is also based on triangular numbers, but we have to account for the lack of floor cards on the bottom story. The number of floor cards for an -story house is the triangular number:
I suppose it shouldn’t be a surprise to learn that triangular numbers play a role in building triangular houses.
Adding the floor and wall cards together, we get
You can confirm this by checking it against the table above.
Now that we have the formula, we can answer the question. We solve
for . This is a 2nd-degree equation, which we can put in standard form,
and use the quadratic formula to solve:
The positive solution (which is the one we care about) is . Because this is an integer, the full answer is Yes, we can build a house like this with 100 cards. It will have 8 stories.
(Since we all have computers, another obvious solution is to make a spreadsheet with one column of stories and another with the formula. When the number in the stories column is 8, the number in the cards column will be 100.)
When I opened the link to see SciAm’s solution, I was surprised to see that they didn’t do it my way. Instead, they used the table of stories and cards to take differences, like this:
The 1st differences come from subtracting sequential elements in the Cards column:
Similarly, the 2nd differences come from subtracting sequential elements in the 1st differences column:
(The SciAm article includes a 5-story house, which has 40 cards, so it also includes another set of differences. I didn’t bother with the fifth house because I figured 4 stories was enough to get the idea across.)
Since the 2nd differences are constant, the formula for the number of cards must be of the 2nd degree. Differences are like derivatives, so if the 2nd differences are constant, so must be the 2nd derivative of the underlying equation. Therefore, the highest powered term in the formula for the number of cards must be a multiple of .
In general, a 2nd degree formula will be of the form
and we can figure out the three coefficients by plugging in three values for and solving the resulting three simultaneous equations:
The solution is
which, of course, matches the solution we got using triangular numbers.
While it was very easy for me to write “The solution is,” solving three simultaneous equations by hand is actually a pain in the ass, so I don’t much care for SciAm’s solution. Too much effort.
But I’ve never spent much time doing difference calculations, and looking at the difference table, I wonder whether there’s an easier way to get the coefficients from it. I’m sure it’s no coincidence that the 2nd derivative of
is 3, the same as the 2nd differences in the table. So SciAm could have figured out that the value of is straight from that. And I suspect there are similarly clever ways to work out the values of and directly from the difference table without going through the labor of simultaneous equations. Maybe I should spend some time learning more about difference tables.