Skip to content

Shuffling Cards

So last week I entered this programming competition and one of the questions was about permutations of letters. Essentially, there was some string of letters and we had to count how many permutations of that string were substrings of a larger string we were given.

The details don’t really matter, the main point is that at some point pretty much everyone in the competition thought about using the permutations function to solve it. Basically what it does is it takes some string as an input and outputs all of the permutations of that string. For example if you gave it ‘abc’, it would output: [‘abc’, ‘acb’, ‘bac’, ‘bca’, ‘cab’, ‘cba’].

Now this was all well and good for small 3 letter strings, but what a lot of us didn’t initially realise was the sheer number of permutations that came with even slightly longer strings. Even when you just increase the input to strings with 10 characters, the function outputs over 3 and a half MILLION strings. Somehow none of us realised how impossible using this function would be, and I think it comes down to the fact that humans have a pretty terrible idea of how fast factorials grow. So let’s talk about it using cards.

Alright, let’s suppose you’re shuffling a deck of cards. Every time you shuffle, the 52 cards fall in some arrangement. We can count the total number of arrangements possibly quite easily. For our first card, we have 52 choices. For the second, we have 51 (since we’ve already used one card), for the 3rd, 50, and so on until we reach the final card. The total product is 52 x 51 x 50 x… 3 x 2 x 1 = 52! (That’s 52 factorial, I’m not just really excited about the number 52) This is what we mean by the number permutations of the deck. This is also the number of strings that the ‘permutations’ function would’ve output if we had given it a 52-letter input. 

The number of possible permutations of a deck

Now, we can write 52! in standard form; it’s 8.06 x 10^67. Simple enough. But that doesn’t even come CLOSE to representing how massive that is. So let’s try and visualise it.

We’re gonna make some assumptions. Let’s say around the world, there are 5000 decks of cards being shuffled every second. Doesn’t seem like too unreasonable an estimate. Supposing every new shuffle made is an arrangement that’s never been made before, how long do you reckon it’ll take to get through all of them at that rate? A couple of years? A couple of centuries? Millennia? The lifetime of the UNIVERSE?

Not. Even. Close.

5000 shuffles a second means 1.61 x 10^64 seconds. That is a LONG time. By contrast, the age of the universe is only about 4.3 x 10^17 seconds. 

Let’s do a thought experiment in an attempt to visualise this length of time. Suppose you’re waiting until that momentous day when, at last, every single possible arrangement of 52 cards will have been done. What can you do to pass the time? I mean, apart from reading Astronomical Blunder Comics? 

Well, you could type out every single word in the Oxford English Dictionary, of course! But don’t worry about being a bad or slow typer. For our purposes, you’re just gonna have to type at the gentle pace of one word every billion years.

Yes, you read that correctly. One word. Every billion YEARS. The sun will swallow up the Earth in its entirety and collapse into a white dwarf long before you’ve finished your first page. And remember while all this is going on, you’ve still got 5000 new arrangements a SECOND being made.

Roughly equal to one word every billion years.

So, there’s about 600,000 words in the OED as of now, and that’s the copy we’ll use. After painstakingly typing out all 600,000 words at that snaillike rate, go take a trip to the Sahara Desert and remove a singular grain of sand (Let’s just pretend the Earth still exists after this time. Nothing else about this scenario is normal either). Delete all those words you spent all that time typing up, and restart from the beginning, at the same rate. When you’ve once again compiled the entirety of the OED, take out another grain of sand from the Sahara.  Repeat until the Sahara is no longer a desert, just a landscape of bedrock. That should be about 1.5 septillion grains of sand, which means 1.5 septillion copies of the OED, all typed at 1 word every billion years.

Now that you’ve reduced the Sahara to just large rocks and gravel, let’s help out the environment a bit. Let’s remove one kilogram of CO2 from the atmosphere (we’re also going to assume no-one is going to be polluting earth anymore because they’ll all be too busy waiting for all the card arrangements to be reached). So, re-fill the Sahara, delete all the words and start typing again. 

It’s a thought experiment, don’t read too deeply into it…

Finish the OED, then remove a grain of sand until you drain the Sahara, then remove a kilogram of CO2. Once ALL of the world’s CO2 has been removed and the atmosphere is completely clear of any carbon…

There will be 1.60 x 10^64 seconds left on the clock. We won’t have even gone through 1% of all the possible combinations. Only once we do that entire process 160 more times, will we have gone through every single permutation. Which means putting back all the carbon in the atmosphere, filling the sahara with sand, starting typing on a blank new document at the rate of 1 word every billion years, and repeat. One hundred and sixty times. 1.61 x 10^64 seconds is a LOOONG time.

This seems almost ridiculously false, because a deck of cards really isn’t all that much; it’s something you can fit in the palm of your hand. Yet the combinations that can be derived from it are barely comprehensible or countable from a human perspective. 

So just know that every time you rearrange your 52 cards, there’s a pretty good chance that it will be the first, and probably only, time that specific arrangement is made for all of human history. If you’re ever feeling unspecial and want to create a historic new moment that will likely never occur again…

Shuffle a deck of cards. 

Sex, Graph Theory, and why you’re taught math

Math, am I right? 

Calculus, trigonometry, geometry, algebra, statistics, proofs. Who needs all of that, and why is everyone forced to learn it at school? Except for mathematicians, of course. And perhaps the odd theoretical physicist or computer scientist. 

Well, ask the sociologists behind this book. More specifically, a claim they made based on surveys saying that men in the U.S tend to have more opposite-sex partners than women. By a LOT. Supposedly the average American male has 74% more female partners than females have male partners. Ugh, men and their promiscuous playboy ways. Typical.

Actually, not quite so. In fact, there’s no way the ratio can be that different, and perhaps if the sociologists knew a bit of math beforehand, they’d be able to dismiss the results of the surveys much more easily. Let’s go through it with a little bit of graph theory.

If you’ve ever done one of those connect-the-dot puzzles, you’ve already indulged in what graph theory is all about. Formally, a graph is a pair G = (V, E) where V is a set of vertices and E ⊆ {(u,v) | u, v ∈ V}. But really, it’s all about dots and lines connecting them. 

ProTip if you want to make your child seem like a prodigy, just say this every time he does a connect-the-dots puzzle.

We call a dot on a graph a vertex and a line from one dot to another (or from one dot to itself!) an edge. So to visualise the population of sexually active men and women, let’s create two columns of vertices as below:

Note that the diagram doesn’t show exactly how many men and women there are.

Now, if a man and a woman are partners, let’s connect them with an edge (for now, we’ll just assume random, arbitrary partnerships and disregard same-sex relationships). Each vertex can have one or more edges connected to it.

Notice that every edge is connected to BOTH the men and women column

OK, so now we’ve visualised the scenario using graphs. Going back to our goal, we’re trying to find the average number of partners of the opposite sex for both men and women. Converting that into our graph theory lingo, that means finding the average number of edges connected to a vertex for each column. Well, to do that you just add up the number of edges connected to all the vertices in one column, and divide by the number of vertices. 

Let’s call the total number of men Vm and the total number of edges connected to the men column Em. Similarly, the total number of women will be Vw and the total number of edges connected to the women column will be Ew. So the average number of opposite partners for men is Em/Vm and for women it’s Ew/Vw.

So the ratio of average partners of men to average partners of women is (Em/Vm)/(Ew/Vw). But Em and Ew are the same. Obviously. A five-year-old looking at the graph could tell you that, since each edge is connected to one vertex from the men column, and one vertex from the women column. In simple terms, it takes two to tango. So the ratio of opposite partner relationships between men and women is simply the ratio of the NUMBER men to women: Vm/Vw

When you look at it this way, it seems ridiculous that men have 74% more opposite sex partners on average. If that were true, it would imply that there are 74% more sexually active men than women in the United States. And even if THAT were true, the number tells us nothing about the promiscuity of men or women at all, it’s just a ratio between the NUMBER of men and women present.

Now, it seems almost comical that the sociologists didn’t notice this simple fact, but that’s the issue: people largely underestimate the role of mathematics, in everything. Math isn’t just adding and multiplying numbers so you can calculate your bills or fill out your taxes. It’s a way to build rigorous arguments and present and analyse things in different ways. We aren’t taught math because the formulas will come in useful one day; most of them won’t. It’s necessary because it strengthens our logical thinking and reasoning abilities, something you need regardless of your interests or profession. 

So maybe don’t be so hard on math. And this may be a math nerd saying that so you can call me biased, but all you have to do to prove me wrong is build a rigorous argument using logic and base axioms, and we’ll agree to disagree.

‘The Office’ and High-School Stress

So, it’s been about one day since school started and I’ve already experienced the crushing pressure of high-school about 12 times! Because obviously if I don’t get all my work done I won’t get a good grade, which means I won’t get into a good college, which means I won’t get a good job, which means my life will be spent unsatisfied and unhappy. Right? Well, recently I’ve started thinking maybe not. And what prompted this shift in perspective, (asks no-one)? An office. But not just any office. THE Office.

In my humble but always correct opinion, The Office is one of the greatest sitcoms, if not THE greatest, to ever grace our television and computer screens. It’s ridiculously funny but not obnoxious about it with a laugh track(maybe I’ll make a future post about my hatred of laugh tracks), it has well-developed characters that grow and, most importantly, it taught me a lot about the stresses of high school.

One of my favorite things about The Office is that the premise is so seemingly monotone and drab it’s a wonder how anyone thought of making any TV show out of it, much less a timeless and legendary piece of comedy. It’s hard to imagine something more bland than the lives of a few workers in a regional paper company, but the way the show reveals the colorful, vibrant, hilarious lives that these average people lead is truly something to marvel at. 

Jim doesn’t just sell paper, he plays pranks at work and designs games for his coworkers and starts his own business. The humble receptionist Pam goes to art school, invents her own job, and paints murals for the building and the city. Dwight owns a beet farm and comes into work dressed as a Belsnickel. Each and every one of the people who work there is an interesting character that we grow invested in and become intrigued about, despite them being nothing but paper salesmen and accountants in a mid-sized distributor. 

Creator Greg Daniels used a visual metaphor to describe the atmosphere and feel he wanted the show to have. He described the show as a paved over concrete parking lot with one single flower peeking through a crack in the pavement. What I think he meant by that is that the show is a satire on this bleak office environment that the majority of Americans inhabit, but it still has this soul. That one flower coming through the crack symbolises the heart of the show, the potential for growth, the beautiful little things that go unnoticed in our busy lives. 

Fun fact: This shutterstock image is also visual metaphor for my social life.

In high-school it’s easy to feel like if you’re not doing “enough” (whatever that means) to be outstanding and a valedictorian that your life will eventually end up boring and meaningless, nothing but a grey, empty, flat parking lot. I used to think like that, anyways. But I think The Office showed me that wasn’t necessarily true. You could have the funniest, loveliest, most interesting life in the world even as a salesman at a regional paper company. All you have to do is slow down and smell the flowers in the cracks between the pavement.

So enjoy life. Take challenges one at a time and appreciate the little things that make it fascinating. Don’t make it hard for no reason. And as Michael Gary Scott would say, that’s what she said

The Pareto Principle

The world’s top 40 most populous countries (out of nearly 200) make up 80% of the human population. The most frequently used 18% of words account for over 80% of the content of any text. The richest 20% of the global population own about 80% of all the money in the world. What’s going on here?

This, in essence, is the Pareto Principle, often dubbed the 80-20 rule. It’s a theory that for any event, 20% of the causes are responsible for 80% of the effects. Although, the numbers don’t have to be 80-20, and they don’t have to add to 100. They can be 70-25 or 90-15, for example. The main idea is that not all causes are born equal, and that there is an uneven distribution on how much of an effect each cause has. Let’s look at some more ridiculous examples.

The most well known and researched example is Zipf’s Law. Now, specifically Zipf’s law states that in any given text, graphing the frequency each word appears in and the rank of that word in terms of frequency on a log-log scale should produce a straight 45 degree line

Source: plus.maths.org, using data of their own website’s word distribution.

Now, this very much should seem surprising to you, unless you’re a robot. We’ve always thought of language and literature as the very opposite of math: it’s subjective, fluid, idiosyncratic. It seems wholly unbelievable that both Shakespeare’s Hamlet and Darwin’s Origin of Species – two works written by different authors at different time periods for entirely different purposes – both follow such a simple mathematical rule.

A log-log graph of word rank vs word frequency in Alice’s Adventures in Wonderland, Hamlet, David Crockett and The Origin of Species, all showing a linear trend for the majority of words.
Source: Ferrer-i-Cancho, Elvevag, 2010

Another big example: Economics. In a lot of cases, and I mean a LOT, Pareto’s principle applies. In the early 20th century Vilfredo Pareto, the Italian economist after which this phenomenon was named, showed that roughly 80% of Italy’s land was owned but just 20% of its people. In 2018, statistics showed that the top 20% of earners in the US payed between 80-90% of the total federal income tax collected. 

Let’s go back again to that statistic about the richest 20% of the world owning 80% of all global assets. Pretty standard example of what I’ve shown you so far. But what if we apply it again? The richest 20% of that 20% should own 80% of that 80%. In other words, the richest 4% should own 64% of the world’s wealth. Apply it again, and we get the richest 0.8% should own just over HALF of the all the money in the world. And Oxfam statistics for 2015 and Credit Suisse’s 2013 report BOTH confirm this, showing the top 1% owning over 50% of global wealth.

Source: Oxfam Statistics

Again, it really should blow your mind that this simple distribution should apply in so many cases, even when iterated. Economics is notorious for its over-generalization and abstraction of the complexity of markets, businesses and entire countries. Money is circulated and flows through a multitude of facets for numerous reasons by billions of people all over the globe simultaneously. Yet we can predict the distribution of the world’s wealth across multiple scales using but a simple power distribution. 

Now, it’s all well and good using the Pareto Principle to notice large trends in the world, but it can help you out a whole lot in your day-to-day life too. Look at it this way: 80% of your problems can be solved by changing 20% of the causes. 

Let’s take a classic example: trying to lose weight. It can be challenging and there’s no shortage of different advice from different people. But just remember that 80% of your calories will likely come from 20% of your food. Thus, just by identifying and cutting a tiny part of your food, you can dramatically reduce your caloric intake. You don’t have to halve your breakfast, lunch and dinner, you can just not eat that 200 calorie chocolate bar.

And businesses LOVE this principle. Several “rules of thumb” in business are based on this simple power law: 80% of your complaints and your income are from 20% of your customers.

And lastly, 20% of what you read and watch ends up taking 80% of your memory. I surely hope this post finds itself into that 20%.

Blunder #1

So, here I am. A (very) lost and confused teenager who has little to no idea what he’s doing, but he knows he likes science, jokes, and science jokes. I like to think of myself as a pretty funny guy, but the empirical evidence for it is dishearteningly low. So I decided to create a new outlet for my insuppressible desire to tell terrible science, math and literature jokes: a comic of stickmen. And now, I am resorting to write blog posts that likely no-one will ever read. 

Wow, I have no life.

Moving on from my depressing lack of social eminence, my comic has got more attention that I had initially anticipated. I mean, I was expecting like 5 people to follow me, and 4 of them would be my friends, and the other would be an instagram bot. But it would seem there are others that actually connect with my sense of humor so much they are willing to expend the Herculean effort of tapping twice and liking my photo, and then tapping once MORE and following me. I didn’t really need validation to continue this comic in the first place, but I can’t deny it feels good having some.

So, about the comic. When it comes to art, my 8th grade art teacher can attest to my startling lack of any artistic proficiency, hence why I use stick figures. If I’m trying to impress someone, I’ll probably make up something about “adopting a minimalist aesthetic to place emphasis on the idea rather than the artwork,” but in reality it’s just because I can’t draw. Then, of course, is the question of the astronauts.

For as long as I can remember, I have been obsessed with space and the cosmos, and since then it’s pretty much become part of my personality and aesthetic. That means listening to space-themed rock bands like Starset, having astronauts as my profile photos on every social media and of course, having astronaut helmets as the main motif of my comic. 

I’ve always held an enormous amount of respect for astronauts. They’re the pioneers of mankind’s exploration, daring to venture into frontiers unknown, unwavering in the face of the cosmos’ enormity and indifference. In a way that’s sort of what I’d like to be. Not on a scale as groundbreaking and trailblazing as them, but perhaps emulating some of those qualities in my own life. I’d like to discover things never discovered before, prove theorems never proved before, make jokes never made before. Of course, the path and journey won’t be easy, and I’m bound to mess up and fall down now and then. But I guess this is where I start. An innocuous, little stick-figure comic. My very first Astronomical Blunder.