Houses of cards and triangular numbers

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:

Triangular houses of cards

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 n numbers is the triangular number

n(n+1)2

So the number of wall cards for an n-story house is twice the associated triangular number

2n(n+1)2=n(n+1)

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 n-story house is the (n1) th triangular number:

(n1)[(n1)+1]2=n(n1)2

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

n(n+1)+n(n1)2=3n 2+n2

You can confirm this by checking it against the table above.

Now that we have the formula, we can answer the question. We solve

3n 2+n2=100

for n. This is a 2nd-degree equation, which we can put in standard form,

3n 2+n200=0

and use the quadratic formula to solve:

n=1±1 24(3)(200)2(3)=1±24016 n=1±496

The positive solution (which is the one we care about) is n=8. 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:

Stories Cards 1st diff 2nd diff
1 2
5
2 7 3
8
3 15 3
11
4 26 3

The 1st differences come from subtracting sequential elements in the Cards column:

72=5 157=8 2615=11

Similarly, the 2nd differences come from subtracting sequential elements in the 1st differences column:

85=3 118=3

(The final 3 in the 2nd differences column is there because the SciAm article includes a 5-story house, which has 40 cards. I left that house out 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 n 2.

In general, a 2nd degree formula will be of the form

an 2+bn+c

and we can figure out the three coefficients by plugging in three values for n and solving the resulting three simultaneous equations:

a(1) 2+b(1)+c=2 a(2) 2+b(2)+c=7 a(3) 2+b(3)+c=15

The solution is

a=32,b=12,c=0

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

3n 2+n2

is 3, the same as the 2nd differences in the table. So SciAm could have figured out that the value of a is 32 straight from that. And I suspect there are similarly clever ways to work out the values of b and c directly from the difference table without going through the labor of simultaneous equations. Maybe I should spend some time learning more about difference tables.