- MCP server with stdio transport for local use - Search episodes, transcripts, hosts, and series - 4,511 episodes with metadata and transcripts - Data loader with in-memory JSON storage 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
149 lines
24 KiB
Plaintext
149 lines
24 KiB
Plaintext
Episode: 1189
|
|
Title: HPR1189: Part One: Counting Partridges and Gold Rings
|
|
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr1189/hpr1189.mp3
|
|
Transcribed: 2025-10-17 21:18:33
|
|
|
|
---
|
|
|
|
Hi, this is Ken, just a short note to say that this is a release of an episode that was released in the last week or two.
|
|
I unfortunately sent down the wrong episode and apologies to Charles and NJ for doing that.
|
|
And this is the corrected episode if you could delete the other version and please listen to this version.
|
|
I would appreciate it. Thank you very much.
|
|
Hello and welcome to Hacker Public Radio.
|
|
This is Charles in New Jersey and I'm back with Part 1 of the two-part episode called The End Days of Christmas, Introduction to Recreational Math.
|
|
Part 1 is titled Counting Partridges and Gold Rings.
|
|
This, as I said before, was the first series on HPR that talks math and today we're going to do it with some attitude.
|
|
Part 0, if you stayed with me long enough, we discussed calendar counting where we learned to count from the opening cocktail party of a convention, not from the keynote, to know which day of the month was on each date of the conference.
|
|
And for locating the beginning and end of a date range that starts on a given day that's not the first of a month.
|
|
I think we're going to be stepping on the panel just a bit. Part 1 today, this is sort of an advanced episode where we're going to start to count other things.
|
|
And since we're counting increasing sequences, we're going to need more than fingers.
|
|
There's going to be a couple of magical formulas at the end that I am going to pull out of my ear and invoke as though I could assert that they're true.
|
|
Since we've been using them for hundreds of years, I guess we can assume that. And for this one, I actually created a spreadsheet version that gives you the brute force table driven calculation so that if you want to skip the elegant formulas, you can just download the spreadsheet or build your own from the instructions here and just do the calculation by brute force.
|
|
That's probably close enough if you really care about getting to these kinds of answers. I think the principle of the thing is the main part, but if you want to take a look at what it looks like in a spreadsheet, you can have a spreadsheet because it's fun to play with.
|
|
Okay, this series was inspired once again by a traditional Christmas song that is somewhat annoyingly repetitive, but it does introduce some mathematically interesting concepts, at least for recreational math.
|
|
I will spare you the experience of having me sing it that would be painful on many levels. So let's step up to the problem. Now in true mathematical fashion, I'm going to avoid taking on the problem head on or even stating it.
|
|
But what we're going to do is look at this song that refers to the 12 days of Christmas and on each day, there's one gift on day one, two gifts on day two, it's an increasing sequence.
|
|
We're going to sum that, and if you'll remember the part of the song that makes it really annoying unless you're actually singing, it's like the garlic of music.
|
|
It's okay if you're singing it, but it's not okay for everybody else who happens to be in the area. So the 12 days of Christmas is the garlic of music, but I digress here.
|
|
Because there's this countdown at each day, I also extended the problem of just counting the gifts, which would otherwise be just one plus two plus three plus four and so on, to what if the true love who's giving these gifts was also wealthy,
|
|
and heard this song that gives the rundown for each day and wants to keep up with whoever's doing this giving.
|
|
So they give the partridge and the pear tree on the first day, then they give another partridge and the two turtled ups on the second day because of the countdown.
|
|
And then they give the three French hands and the other three birds, so they're giving a gift here, three gifts there, six gifts there, and so on.
|
|
So it adds up really quickly. Well, we're going to find some ways to first organize our attack on how to do this, these kind of problems by doing it in the spreadsheet, but then we're going to pull some algebra magic that you should have learned in high school if you've been paying attention.
|
|
And I just apply it because we're not in school, we're on HPR, I can just pull these formulas out of a book, look them up, and we can use them. So that's sort of an advantage.
|
|
Now I'm going to start with a simpler problem, sort of like the Fedora people, they want to assume they have a cow they want milk, they want to assume a spherical cow like a physicist would.
|
|
Well, we're going to build up the problem in four steps, step zero is I get a gift on Christmas day, and that's it.
|
|
Well, my cumulative count on Christmas day, day one is one, since I didn't get anything on the 26th, my count on the 26th is one, the 27th, it's still one, and so on.
|
|
So that's step zero, pretty easy to count. I'll give you the answer, one.
|
|
Now step one is I get a gift a day, so that my increments are one, one, one, one, one, and get gift each day, but my cumulative count is now one, one plus one, one plus one, these are the counting numbers.
|
|
The numbers that we were using implicitly when we were doing this finger math of counting things on our hands and fingers, and that we use all the time when we were in base 10, except we're doing it with symbols and algorithms that they taught us in school, or with computers instead of fingers and hands and physical things.
|
|
Okay, so step two would be the idea that was supposed to be in the song of having one gift on the first day, two on the second, three on the third, four on the fourth, and so on up to 12 on the 12th.
|
|
And then step four is the final thing based on the misinterpretation, just for fun, instead of having just the one gift and then the two and the three will have one, then one plus two, then one plus two plus three, one plus two plus three plus four, and so on.
|
|
And we'll sum that series based on the cumulative values, so each time we're sort of stepping up a level in the way these gifts mount up and boy do they mount up.
|
|
The first place where the formula start getting, or the arithmetic starts getting hairy is with the case that's in the song, where we're giving one gift here, two gifts there, and then three gifts on day three, and so on.
|
|
Notice, just for fun, that stage zero, where I had just the one gift, if I now open a spreadsheet, which I'm tempted to do because the numbers are getting big, I could start with four columns and handle this whole thing.
|
|
Actually, give me five because I want to number the rows of my spreadsheet from zero to about 0, 14, so that when I do this, I'll be able to recognize what row I'm in, so I can apply the formulas from my magic theorem and get my formula falling out into my lap.
|
|
So I'm going to open a spreadsheet, and in column A, let's say row one, I'm going to start with row one and go down to 15 and put the number zero to 14 in there, and don't particularly care what spreadsheet, and I don't care how you do it.
|
|
Okay, you've probably done the next column over, I want to put in column B one through 15, I want to put all ones, 1, 1, 1, 1, 1.
|
|
You might recognize that as the cumulative total of step zero, where I've just done the one gift on the first day, no gifts after that.
|
|
The accumulation is pretty easy, there isn't any, and we just put the cumulative totals.
|
|
In column C, I want to do running sums of the previous column with just the ones, and why do I want to do that? Because that's what I'm essentially doing by having a gift each day.
|
|
I start with day one, I've got that one gift on day two, I've got two gifts in the step one scenario in column C.
|
|
So that's the gift that I had yesterday plus the new gift from today, and that makes two, and then the two gifts I've already received plus the new gift on day three makes three, and so on.
|
|
I'm going to talk about two ways to set up this running sum formula, because I've seen this in spreadsheets, and I think people aren't aware of what's happening there.
|
|
So there's two ways to set this up. You can, in column C, where we're setting up this running sum, we can have this sum formula, and use the facility in a spreadsheet program to put in an absolute reference at the top of the column, and then put a relative reference that also points at the top of the column.
|
|
So I'm basically just pulling the value from the top of row B over. I'm just pointing to B1, and this is all in the show notes, you'll be able to see what the formulas say.
|
|
And then copy that down, and as I copy it to row two, I'm now summing from one to two, and row three is summing from one to three, and so on.
|
|
Which is fine, it'll work, it'll do a running sum, but what you're doing is a lot more addition operations than you need.
|
|
Because when you do a running sum, the adds the numbers from one to twelve, and you've got every one of those incremental sums, well the twelfth sum of one to three, four, five, six, seven, eight, nine, ten, eleven, twelve, is equal to the sum of the first eleven plus the twelfth entry.
|
|
So what you could do is at the top of that column, see, just make the first formula C1 equal B1, C2 now is equal to C1, the previous value, the previous sum, plus the new value in B2.
|
|
That you can copy all the way down, and it comes up with the same answer, but as we will see, it has a lot fewer operations, especially as the number of rows gets really big.
|
|
And because of the way we've constructed this, the next column over is the answer to how many gifts do you get if you just do the partridge on the first day, the two other birds on the second day,
|
|
I guess there's still birds on the third day, birds on the fourth day, and finally something worthwhile, the five gold rings, and so on.
|
|
That's the next column, and if you do running sums of one, two, three, four, you get one, three, six, ten, fifteen, twenty-one, stop me before I kill someone.
|
|
Okay, those are what they call the triangular numbers, and the reason they call them triangular numbers is if you take one, two, three, four, and you take blocks, and put them next to each other in columns where you've got a single block, then two blocks next to it, and then three high, and then four high, it makes a triangle looking thing.
|
|
And that gives you an idea of what those numbers are for, and you can, okay, if I've got any of them, I know that there's this formula that they taught me that was n times n plus 1 over 2, and okay, great.
|
|
I know how large that number is.
|
|
We'll actually have that formula fall out of what we're doing, so hang on for that, because we won't have to do much deriving, we'll just have to assume that the binomial theorem is true, and just pull out the corresponding one formula that we want and say, there, that's my answer.
|
|
So if you stay tuned, we'll have that.
|
|
Now step three, where the person made a mistake, and confuses the rundown for their shopping list for the day, they're giving one gift on day one, which is fine.
|
|
But instead of giving two gifts on day two, they give three gifts on day two because of the rundown.
|
|
So now they've given four in all, and then on the next day, they give the three gifts plus the two plus the one, and they've already given four, so now they're up to 10, and these are what they call the, oh gosh, I think they're the tetrahedral numbers.
|
|
If you want to understand why they call them tetrahedral numbers, just imagine having five sets of billiard balls, numbered one to 15, and the first set you'll put in a rack with a familiar arrangement with one on top, then two in the second row, then three in four and five, and then you'll see that in the spaces between every set of three balls,
|
|
there'll be a space that you could pile one ball on top of that, and it so happens that if you've got the traditional rack of billiard balls with the rows one, two, three, four, and five, you can actually put in the spaces between those, a second tier of balls that are arranged in four rows, ten and all, one, two, three, and four, which is the triangular number just below 15, which is the sum of one to 15.
|
|
On top of that, you could put one, two, three in order, and that would give you six, which is the triangular number below that, and then one, two, three would fit in the spaces between those, and then one on top, and you'd have a tower that has three sides, and a triangular base, and that is a tetrahedron.
|
|
There's a really nice picture that they made of a tetrahedron with a small number of marbles arranged in just this sort of way on the math is fun website, and it's just kind of cool, you can probably win at trivial pursuit if you know this.
|
|
Very cool, so let's move on.
|
|
Now to see pictures of this, really cool pictures, you should go to the extremely nerdy site called www.mathisfun.com, and if you go to the article on Pascal's Triangle, which is pointed to in the show notes,
|
|
you'll see nice illustrations of not only the triangle numbers, but the tetrahedral numbers, they've got links to that, and you'll see the general shape of this triangle,
|
|
which is also explaining how this is leading us to answers.
|
|
What we've done is taken the classical Pascal's Triangle that you learned in algebra, and promptly forgot, you can be forgiven for that.
|
|
We've just turned this sideways so that the diagonals are going down our columns.
|
|
The rows are actually diagonals in the spreadsheet, so if you load up the spreadsheet in your computer, and then twist your monitor around,
|
|
rotated about old 60 degrees, you'll see that it looks kind of like the array that's in the Pascal's Triangle article.
|
|
Now if your monitor is on a stand or anchored to your desk, don't do that because you could be damaging a furniture and so on.
|
|
But that's sort of what we're doing and how it looks.
|
|
Okay, so we've got the idea that we can just do these totals for any end days of Christmas by looking at the 12th row in that spreadsheet that gives the answers so that for the step zero, which is the one gift and no more,
|
|
where you can read the number one off that row.
|
|
It would be, yeah, 12th in the array, I think it would be technically row 11.
|
|
And then right next to that is 12 in diagonal one, and that's the number you get if you get one a day.
|
|
If you do the one, two, three, and so on, the sum of those is 78th in the spreadsheet and doing this running, running some maneuver on that column, I get 364 gifts if I'm doing the 12 something or there's 11 pipers piping, 10 blah, blah, blah, and so on.
|
|
If I do that countdown every day and give all those gifts over and over again, I get 364 gifts, which is pretty steep, but that's how many are named.
|
|
So you've got a way to get to this by brute force because we've got the spreadsheet and a general way of doing it.
|
|
Now it's time for the magical part. And because I'm playing with Pascal's triangle, I can essentially just write down formulas for the total number of gifts after N days for N days of Christmas for step zero.
|
|
It's pretty easy. We have one gift, but technically this is something like N minus one choose zero, which is a binomial coefficient.
|
|
And find this function that's the number of ways you can choose a certain number of items from a larger number of distinct objects independent orders so that ABC and CBA are the same as long as A and B and C are all in there.
|
|
Those would be the same combination and systematic of if you're choosing from A through L, which is 12 objects, then ABC would be one possibility of choosing three objects.
|
|
But in this case, it's how many ways can I choose zero from any number of objects and that would be one.
|
|
Nice that it fits a pattern, but who cares step one is a little bit more important because that shows us how we're getting to this and that's N gifts is the total after after N days because we got one a day.
|
|
But if we lift the formula out of Pascal's triangle by noticing the correspondence to the binomial theorem, it would actually be N choose one, which is that big parentheses thing with the number N over the number one physically over it, but not a fraction.
|
|
It's actually a binomial coefficient and you can compute that with the Combin function in say numeric, I think it's also in a certain proprietary spreadsheet product as well, but it fails for large numbers where Combin in numeric actually works better.
|
|
And to show you an example, if you do equals Combin 12 comma one, you get 12, which is correct.
|
|
Okay, step two is that one, two, three thing and we suspect that we're going to get N plus one over two because that's what we were told, you know, we either we're told that we remembered it or we remembered that trick of taking the numbers one to 10 and then lining up the numbers in reverse order and then pairing them up.
|
|
11, you know, one in 10 is 11, two in 9 is 11 and so on. We got 10 of these pairs. So it's the pairs together add up to 110. But since we had everything twice, it's 11 times 10 over two or 55.
|
|
But in this case, we're just taking it off the binomial theorem. So we have because we're lining things up in that Pascal triangle on a different diagonal, we've actually shifted down a row to do this second level of accumulation.
|
|
We're not just doing the counting numbers now, we're doing the running sums of the counting numbers. So now the answer is N plus one choose two for the sum of the series and that's N plus one times N over two times one.
|
|
Now, for me, to remember how to do these combination things, what I usually do is think them in terms of, well, the math people call them factorial products, but I'm going to call them countdown products because that's sometimes easier for people to remember.
|
|
And if I've got N plus one choose two or combine N plus one comma two, that's a fraction where that both the top and bottom upstairs and downstairs are defined using a two term countdown product starting at the numbers in order in the arguments.
|
|
So in the case of common N plus one comma two, it's the two term countdown products starting at N plus one, which is N plus one times N plus one minus one, which is N.
|
|
And then the two term countdown products starting at two, which is two times one or two. So that gives us back our traditional formula when N equals 12, that's 13 times 12 over two, which is 13 times six or 78.
|
|
Now, you can always count on this kind of canceling to happen in this kind of formula, especially with the smaller denominator because when you have two consecutive numbers, one of them's got to be even.
|
|
So this one's going to work out. And the next one will work out because it's going to involve a three factorial or a three fold countdown product in the denominator, but I'll get to that in just a second.
|
|
Okay, as an aside, there's an additional thing we can conclude out of this and that is we can actually count now the number of ads for the naive running some with 12 terms.
|
|
The naive sum will just be pulling the value for the first term. So that's no additions. There could be some fetches in there and so on, but I'm going to assume that you can do all those at the same speed.
|
|
Even if that's not quite true, I'm going to say that the ads are the expensive thing. So zero ads for just pulling the first number.
|
|
The first running sum is the first number plus the second. So that's one addition. It's two numbers, but it's one operation.
|
|
So I'm adding zero, one, two, three, four down to 11 because I in the first position of the 12, I have zero. So for me to go zero to a count of 12 items, I'm going to count from the cocktail party and I'm going to have 11 because the cocktail party is at minus one.
|
|
So so zero to 11, I just plug this into my formula. It gives me instead of common 13 to because of the n plus one thing. This n plus one is actually at 12.
|
|
So the number of operations is 66. Now, if we actually look at our spreadsheet and we look at the step two column on day 11, we can actually see that the brute force number in there is 66. So we're on the right track.
|
|
Now, as the number of rows gets bigger, this n times n plus one over two is going to get pretty close to n squared over two ad operations.
|
|
And people refer to this as big O of n squared. The running sum is over a column by adding everything up by total brute force with the zero additions, the one addition and so on.
|
|
That is called big O of n squared. That's the number of ads, which means that the number ad operations is proportional to n squared and not not proportional to n.
|
|
Now, if I use my recursive thinking formula where I just say, okay, the sum of n objects is the sum of n minus one plus the nth.
|
|
Then I'm only doing one ad per row for those 11 rows and I'm just doing no ads when I copy the first element.
|
|
So I've got n minus one or big O of n operations doing it that way. So if I were to, let me just go to my spreadsheet, which has a page that compares these things.
|
|
So if I've got, say, 10 rows, I'm not really going to notice the difference in a recalc on the spreadsheet because the number of ads in this running sum, you know, the sum of the addition operations is going to be like 45.
|
|
And if I use my recursive thinking form where I add each new row to the last sum that I computed, I'm only going to have nine ads in 10 rows.
|
|
So on the computer, this is going to make much of a difference. If I have 100 rows, that number of ads jumps up to almost 5,000, whereas the ads in the recursive thinking approach where I'm just adding the new row to the old sum, that's going to be 99 or about 100.
|
|
Now that when you get to 1,000, then you're talking about 500,000. If you get 10,000, that's almost 50 million. And 100,000 rows, that's 5,000,000 ads as compared to 100,000 ads doing things in the recursive thinking mode.
|
|
So if there's one thing that you remember from this episode, besides the, of course, two things you should learn from the whole series. One is count from the cocktail party, not from the keynote.
|
|
And the second is this. If I'm doing a running sum that's stored next to a big block of data, I want to think recursively.
|
|
I just say it again. I want to think recursively. I don't want to, I don't want to copy a formula where I am adding every number over and over and over and over and over and over again.
|
|
And I said it that many times because if you've got an operation that's n squared, you're going to be saying that n over a lot of times when you've got 100,000 rows.
|
|
If you insist on doing it that way, I'll help you never get above 1,000 rows of data or you will be old before your spreadsheet three calculate.
|
|
Okay. Let's see. I think I've covered almost everything that I want to talk about.
|
|
The final point I wanted to pass along a homework question. In the previous episode, I asked, what if they were 72 days of Christmas?
|
|
And my question then was when will it end? Well, that was pretty easy. We knocked that down by making it easier.
|
|
Here's the question now. How many gifts would be given in total per steps 0, 1, 2, and 3 if there were 72 days of Christmas?
|
|
If you were following along, you'd either have the spreadsheet, do some copies and you're done or you'd know the magic formula, you could plug in some numbers and you'd be able to get the answer.
|
|
So if you've really followed what's been happening in this episode, you'll be able to do that calculation.
|
|
What I can't guarantee is that you'll find someone who cares that you can answer a weird question like that. I can guarantee that there will be a lot of people who look at you funny if you do actually start posing that question to them.
|
|
Okay. Well, I hope everyone has a happy holiday season and we'll see you at the New Year's Eve show.
|
|
My contact information, I'm Charles in New Jersey. My email is catintp at Yahoo.com and I'm not going to spell it phonetically because I get such a load of grief from the admin.
|
|
Thanks Ken for doing the editing and we'll see you soon. I hope to listen to your podcast on hacker public radio. Thanks a lot.
|
|
You have been listening to Hacker Public Radio at Hacker Public Radio. We are a community podcast network that releases shows every weekday Monday through Friday.
|
|
Today's show, like all our shows, was contributed by a HPR listener like yourself. If you ever considered recording a podcast, then visit our website to find out how easy it really is.
|
|
Hacker Public Radio was founded by the Digital Dark Pound and the Infonomicom Computer Club. HPR is funded by the Binary Revolution at binref.com. All binref projects are crowd-sponsored by lunar pages.
|
|
From shared hosting to custom private clouds, go to lunarpages.com for all your hosting needs.
|
|
Unless otherwise stasis, today's show is released under a creative commons, attribution, share a line, lead us our license.
|