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:

Difference table

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 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 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.


Sinusoidal sunlight

I started my morning walk earlier than usual today, and it was still fairly dark out. I thought about this post from last year and the Daylight line in the graph:

Chicago, IL-2024

I wondered how hard it would be to alter the code to plot the slope of the Daylight line. That would give perhaps a better sense of how rapidly we gain daylight in the spring and lose it in the fall. But I soon decided against trying that for two reasons:

  1. Numerical differentiation (i.e., finding the slope) tends to create noisy data and therefore jagged graphs. I figured this was especially likely with the US Naval Observatory data, since it gives the sunrise/sunset times rounded to the nearest minute.
  2. If the Daylight line really was a sine wave, its slope would also be a sine wave, just shifted by about three months. Not very interesting.

But the second objection got me thinking: how close to a sine wave is the Daylight line? I could try fitting a sine function to the data and see how much the error is. This would give me a chance to learn something new about Mathematica Wolfram.1

Here’s the notebook I made to check the fit:

The first three evaluation cells create a list of (day, daylight) pairs that cover a 16-year period starting on January 1, 2009 and ending on December 31, 2024. I used a multiple of four years so leap years would appear in the same proportion they normally do, at least over the period from 1901 through 2099.

The day is an integer, starting at 0, and the daylight is given in minutes. We usually talk about “daylight hours,” not “daylight minutes,” but because I was going to plot the difference between the actual length of daylight and the best fit sine curve, I thought minutes would be an easier unit to work in.

The daylight list is calculated through the Sunrise and Sunset functions, which give results to at least the nearest second. (They display a time to the nearest second but may keep fractions of a second internally.)

We’re going to fit the data to a curve of this form:

d=m+asin[2π(tf)p]

where

The phase of a sine wave is usually expressed as an angle in radians, but here I’ve rejiggered the equation to give it the same units as time.

The best fit of the data to this equation is found through the FindFit function. Because this is a fit to a nonlinear curve, I thought it best to give decent initial guesses for each parameter,

fit = FindFit[data, model, {{m, 12*60}, {a, 3*60}, {f, 80}, {p, 365}}, t]

The mean daylight value is going to be near 12 hours, so the initial guess for m is 720 minutes. Here in the Chicago area, we go from about 9 hours of daylight in the winter to about 15 hours in the summer, which puts the initial guess for a at 3 hours or 180 minutes. The period has to be about a year, so the initial guess for p is 365 days. Finally, because 12-hour days happen at the equinoxes, our initial guess for f is 80 days, which is about where March 21 lands.

As you can see, the best fit values for the parameters are

{m -> 733.182, a -> 176.722, f -> 79.5656, p -> 365.249}

so our initial guesses were pretty good. Note that the best fit period is 365¼ days, which matches up with the frequency of leap years.

Finally, we get the difference between the actual data and the best fit curve and plot it. The first plot covers the entire 16-year period and is kind of hard to read. The error of each year is basically the same, so we can get a decent idea of how the error varies by looking at just the first year, which is shown in the second plot and reproduced here:

Sine wave error

The largest error (in absolute value) is about 7 minutes at or near the winter solstice. The error varies in a sort of sinusoidal fashion with a period of about 4 months, so the peaks and valleys of the error function are roughly 2 months apart.

You can decide for yourself whether an error like this—7 minutes out of 9 hours—makes the real data “close” to a sine wave. I’d say ~1% isn’t bad for such a simple model. Mostly, though, I’m happy to have learned a little more about the Wolfram Language.


  1. Wolfram Research recently decided to change the name of Mathematica to Wolfram, thereby giving up on decades of branding and ruining Google searches. The name change isn’t complete—you still see Mathematica in several locations in the app—but the executable has the new name. 


Rebar and reinforced concrete

A recent episode of the 99% Invisible podcast, “Brilliantly Boring,” covers a topic near and dear to my heart: reinforced concrete—more specifically, the rebar that does the reinforcing. The show does an excellent job in a short period. I just want to fill in some details.

The show is structured around the Alvord Lake Bridge in Golden Gate Park. Built in 1889, it’s one of the earliest reinforced concrete structures that’s still around. It was designed by Ernest Ransome, the guy who made rebar (almost) what it is today.

Iron and steel bars were used to reinforce concrete before Ransome. Joseph Monier of France is usually credited with starting the systematic study and use of reinforced concrete back in the 1850s. But as far as I know, the reinforcing bars and wires that Monier used were smooth, round bars with no texture or bumpiness. Ransome used bars that were made of square stock that had been twisted, like this:

Twisted bar reinforcement

Image from Walcoom Corporation.

The twist helps prevent the bar from slipping relative to the concrete. This makes them act together, which is how reinforced concrete gets its strength. In the show, they say that the twist “gives it an adhesive quality to the concrete itself,” which isn’t quite right. What the twist does is provide what’s called mechanical interlock. For a twisted bar to slip, it has to both break the adhesive bond with the surrounding concrete and push it out of the way so it can slide past. This extra resistance to slip is what made twisted bars work better.

Nowadays, we almost always use what are called deformed bars, which have little ribs on the surface to provide the interlock.

Deformed bar reinforcement

Image from Walcoom Corporation.

But twisted rebar had a strong run in the early days of reinforced concrete. Many years ago, a friend and coworker of mine was directing some repair work at the Unity Temple in Oak Park, Illinois. This is a Unitarian Universalist church designed by Frank Lloyd Wright at the beginning of the 20th century. One day my friend called me into his office. “You have to see this,” he said, as he handed me a three-foot length of twisted rebar. “This is original Frank Lloyd Wright rebar. I found it in the trash. They were going to throw it away!” So I got to hold a piece of architectural and structural engineering history because of my friend’s dumpster diving.

Why do we need to use rebar? As they say in the podcast, concrete is strong in compression but relatively weak in tension. The usual rule of thumb is that its tensile strength is about one-tenth its compressive strength. This pretty much limits unreinforced concrete to structures that never undergo tensile stresses. But if we put rebar into concrete where tension will develop, that tension will be carried by the steel, and we can use concrete in almost any kind of structure.1

There is a problem, though. The highest tensile stresses tend to occur at the outer edges of structures, right along the surface. So to get the most benefit from rebar, we want to put it as close to the surface as possible. Unfortunately, concrete is porous, and water can work its way in, come in contact with the steel, and cause it to corrode. This has two effects:

  1. It reduces the amount of competent steel, weakening the structure.
  2. The iron oxide corrosion products take up more volume than the original steel. The expansion of the corroding rebar creates an outward pressure on the surrounding concrete, leading to cracking and spalling. This further exposes the rebar, leading to more corrosion in a vicious circle.

To protect the rebar from water infiltration, there are design rules about how far from the surface the rebar must be placed (this is called concrete cover). But as we said earlier, placing the rebar away from the surface makes it less effective in resisting tensile stresses. As in all types of design, there are trade-offs, and here the trade-off is between strength and longevity.

As you may know, salt water is more corrosive than fresh water because of the chloride ions from the dissolve NaCl. So reinforced concrete in coastal environments and northern climates, where salt is used on roadways, is especially susceptible to deterioration from rebar corrosion. If you look up while driving under any number of old reinforced concrete bridges in Chicago, you’ll see plenty of rusted and exposed rebar.

If you want to see Ransome’s work, and are leery of going to the Alvord Lake Bridge (the podcast says it’s in a sketchy section of the park), you can go to the Cantor Center for Visual Arts on the Stanford campus. The original building was built in 1891, just a couple of years after the bridge, and is made of reinforced concrete as designed by Ransome. The building was expanded in the early 1900s, using masonry construction, which was a bad idea. The new wings collapsed during the 1906 earthquake, leaving only Ransome’s work still standing. His part of the building also survived the Loma Prieta earthquake of 1989, the 35th anniversary of which was just a couple of days ago.

By the way, although Stanford’s page about the building says it used “a new method of cast-in-place concrete reinforced with twisted metal rods,” just like the Alvord Lake Bridge, James MacGregor’s well-regarded textbook, Reinforced Concrete: Mechanics & Design, says that while Ransome used twisted bars in other structures, he “used discarded cable car rope as beam reinforcement” in the museum. I don’t know which is correct, but the helically wound wires in cable car ropes would also provide good mechanical interlock.

It took me a while to write this post, mainly because I kept veering off on tangents about Frank Lloyd Wright’s home and office in Oak Park, strain compatibility, the weird belief among some people that Roman concrete was better than today’s, compression-only structures, rebar size nomenclature, and the tendency for concrete to use the waste products of other industries (like flyash and, perhaps, discarded cable car rope). I hope you appreciate how I managed to edit it down.


  1. Yes, I know that rebar is also used to resist compression and shear. I’m trying to keep things simple. 


Expanding

Regular readers1 know that I like to watch mathish YouTube videos from Numberphile, Stand-up Maths, and Mind Your Decisions. Unfortunately, this leads YouTube’s machine learning system to believe that I want to watch all math videos, no matter the level or quality. So it keeps pushing dull videos at me in which an overhead camera records the hands and pen of the presenter writing out line after line of elementary math. There are apparently an infinite supply of these things.

Occasionally, one of these videos has something in the thumbnail frame that catches my eye, and I click on it despite myself. Here’s a video I saw last night that pretends there’s a connection between a binomial expansion and Stephen Hawking. What it really does is solve what it says is a problem from a high school entrance exam. No Hawking at all.

The goal is to simplify this expression:

(21) 10

It could be argued that this is already in a pretty simple form—it’s certainly compact—but in this case, “simplify” means to get rid of the exponent.

If you can bear the tedium of the video, you’ll see that its solution goes through some algebra and various levels of substitution. It takes a very long time, and not just because the presenter insists on writing out every little step along the way.2 The entire approach to solving the problem is inefficient.

Because this is an exam problem, getting the solution quickly is important. To my mind, the fastest solution is to expand the binomial directly. I don’t have the binomial coefficients memorized up to the 10th degree, but Pascal’s Triangle can be built in a jiffy:

                              1                                
                           1     1                            
                        1     2     1                         
                     1     3     3     1                     
                  1     4     6     4     1                  
               1     5    10    10     5     1              
            1     6    15    20    15     6     1           
         1     7     21   35    35    21     7     1         
      1     8    28    56    70    56    28     8     1      
   1     9    36     84  126   126    84    36     9     1   
1    10    45   120   210   252   210   120    45    10     1 

You know how to put this together, right? Each new row starts and ends with a 1, and the other terms come from the sums of the terms in the previous row diagonally to the left and right, e.g.,

10=1+9 45=9+36 120=36+84 210=84+126

and so on. Because of the symmetry, you only have to calculate about half the terms.

So the expansion of (21) 10 is

2 5102 42+452 41202 32+2102 3 2522 22+2102 212023+452102+1

where I’ve used identities like

(2) 10=2 5

and

(2) 9=2 42

to simplify each term in the expansion.

Now we can do the various multiplications and collect the terms with and without the 2 terms to get

(32+720+1680+840+90+1) (160+960+1008+240+10)2

which gives us the correct answer:

336323782

While there may be some cleverness to the YouTuber’s method of substitution and resubstitution, this is certainly more straightforward and less likely to generate algebra mistakes—both of which are important when you’re under pressure during a test. The main thing to remember is that the odd powers of 2 have negative signs and the even powers don’t.

I suppose it’s unfair for me to insult someone who’s trying to help students, but his slow solution isn’t going to be very helpful. And he shouldn’t pretend that his video has anything to do with Stephen Hawking.


  1. Can you be a regular reader of a blog as irregularly published as this one? Discuss. 

  2. Yes, I realize that this is an instructional video meant for young people and there’s value in a methodical pace. But no one who can follow the math in this video needs to see every single addition and multiplication.