Friday, August 30, 2013

Extreme Rock, Paper, Scissors

Few games have captured the hearts and minds of the public as Rock, Paper, Scissors.

Ok, that's maybe not even remotely true. RPS is one of the most basic games on earth that, barring any possible psychological factors, is essentially a glorified coin toss. That hasn't stopped fantastic organizations like the World RPS Society from existing (their 'responsibility code' includes a recommendation not to use Rock Paper Scissors for life-threatening decisions. Good call.), and some people certainly take the game very seriously.

I'm also going to take it very seriously, albeit in a completely different direction. I came across a post on my new favorite blog last week, DataGenetics, where the author created and examined a sort of iterative 'team-based' game of RPS. In his game, people in a group would be assigned to always play a certain play, and then are drawn into random pairings for a show-down. The winners go back into the pool, and the losers get eliminated, until only one 'team' of players remains.

This becomes an interesting examination that, in a way, can sort of approximate population dynamics. If we had an island where wild rocks, papers, and scissors ran around in their natural habitat, where the natural prey of rocks were scissors (they'd viciously bend the blades before eating them), the natural prey of scissors were paper (the blades would tear into the paper velociraptor-style) , and the natural prey of paper was rocks (who would get... covered? By far the lamest of the RPS triad), then if the populations were fairly equal the island would stay at a fairly steady equilibrium. As soon as you remove, say, scissors, the rock population would be catastrophically destroyed by all the unchecked paper roaming around... covering them.

Alright, so it isn't a perfect analogy, but I hope you get the point. As this is a non-transitive food cycle (instead of a mostly transitive food chain), the dynamics are a little bit different than what you might expect in real life, but population dynamics in simple predator-prey models really are rather fascinating.

DataGenetics' results were really cool, though, so I decided to see if I could reproduce them and take them further. The first model he made featured 10 rock players, 10 paper players, and a varying number of  scissors players. What do you think would happen as the population of starting scissors players decreases? Surprisingly, their odds of winning actually increase. In fact, as long as there is at least one scissors player, their odds of winning the whole thing range from 33% to 60%, with a peak when the starting scenario is 10 rock, 10 paper, and 4 scissors.

My results came from running 10,000 game simulations per data point, and almost perfectly match up with the results from DataGenetics, so I'm reasonably confident in them.

What's going on here is actually really cool. Reducing the number of scissors at the outset means that initial pairings between players are going to more likely be between rocks and paper - which paper will (illogically by laying on the rock) win. As the game progresses, it is more likely to become mostly paper and scissors, which is an easy scenario for the scissors to win. This means that unless scissors get unlucky and have a lot of early pairings against rocks, they have much better than even odds of winning the game outright. As DataGenetics put it, this is a great example of the expression "The enemy of my enemy is my friend."

Here's a cool alternative view:

If you run a similar scenario, but with 50 rocks, 50 papers, and a variable number of scissors, the results are even more extreme - scissors' best chance of winning is when they start with 17 players against their opponents' 50 each, where they have a 91% chance of winning the whole game.

The reversal of the trend between rocks and scissors here is also pretty fascinating. At larger numbers of initial players, paper's odds of winning are much more sensitive to changes in the number of scissors than rock's, until the number of scissors becomes drastically low. It's also worth pointing out that my results here deviate a bit form DataGenetics after 25 scissors players, even though I was trying to do fundamentally the same thing as he was. I have no idea who's correct, so I guess it's time for a nerd show-down...

I said I was going to take this a step further, and the nerdiest way of taking Rock, Paper, Scissors further is to change it to Rock, Paper, Scissors, Lizard, Spock.

Good thing the rules to normal RPS are easy, because adding two new options adds seven new combinations to remember. As the Big Bang Theory puts it:
  • Scissors cut paper,
  • Paper covers rock,
  • Rock crushes lizard,
  • Lizard poisons Spock,
  • Spock smashes scissors,
  • Scissors decapitates lizard,
  • Lizard eats paper,
  • Paper disproves Spock,
  • Spock vaporizes rock, and (as it always has)
  • Rock breaks scissors

  • So what if we ran the same game experiment, but with 10 each of the five combinations? If we kept scissors as the changing variable to be consistent, we get the following:

    Now this is just cool. Instead of scissors getting a bonus by losing players from the start, scissors are barely affected at all until their numbers get small enough. While the starting number of scissors is between 4-10, they're still doing about average with 20% chance of winning, after which their chances plummet.

    What's far more fascinating is the other players - poor Spock gets mutilated! Spock's chances of winning are always less than scissors' until scissors has 0 starting players. Why?

    Most likely it's because, even though Spock smashes scissors, scissors is the only player that can kill both of Spock's predators (lizard and paper). As the chances of both of these getting killed decrease, so too does Spock's chances of winning the game. Meanwhile, lizard is having a great time. Its one big predator, scissors, is dwindling in numbers, meaning it more likely will have to face paper or Spock, which it's of course fine with.

    If we bump up the number of starting players to 50 again, we see the true dominance of rock, and again scissors tends to suffer very little (in fact, they're second-most likely to win up until they start off with only 20).

    Very cool indeed, especially if you're rock. Again, poor Spock gets decimated, but in general the behaviors of the other players are largely similar to the previous example, but at a much reduced scale to give way to rock.

    In reality there's virtually no practical application to any of this, except to perhaps point out the unanticipated consequences that may arise when you remove an element of a balanced ecosystem. Population dynamics in the wild certainly don't follow such simple rules, but it's definitely not unheard-of for the addition or removal of a small part of the population of a species to have massive ramifications on other species, and the fact that this can be modeled with math and Rock, Paper, Scissors is pretty cool.

    Thursday, August 15, 2013

    Barenaked Lady Odds

    I'm a fan of (the) Barenaked Ladies. Please feel free to interpret that in any context you wish.

    The band's most recent single, Odds Are, is respectably catchy (alright, I'll admit, I had it on repeat for a couple plays before I decided to write this). The lyrics are also moderately clever, and talk about some of my favorite things (like odds and probability. Yay!).

    Here's a look through some of the lyrics they toss out, and the actual stats behind them:

    Struck by lightning, sounds pretty frightening/ But you know the chances are so small

    The United States of America records an average of 22.8 million cloud-to-ground lightning strikes a year, or approximately one lightning bolt per 14 ‘muricans. Out of all of this lightning, only an average of 34.9 fatalities occur per year. This puts any given American’s odds at getting killed by lightning in a given year at around 0.000011% (much higher if you live in the south and/or play golf, though, so watch out). In fact, you would have to live for about 9,000 years before you’d even have a 0.1% chance of getting hit by lightning. Considering how easy it is to avoid as well (don’t stand near tall things during a thunderstorm), this really isn't something to be all that paranoid about.

    Stuck by a bee sting, nothing but a bee thing/ Better chance you’re gonna buy it at the mall

    Surprisingly, deaths by bee stings are about 70% more common than death by lightning (0.000019% a year). Bee stings are apparently safe enough that the average human can handle 10 stings per pound of bodyweight, meaning that unless you’re deathly allergic you could easily take on over a thousand of the little critters. I guess if you are allergic it might be time to invest in an epi-pen? As for mall deaths, it turns out that the stats on those are pretty hard to find, though I’m sure it’s not terrifically different than the going death rate from walking. I’d recommend avoiding Black Friday in the US, though, since that leads to outright murders…

    But it’s a twenty-three or four-to-one/ That you can fall in love by the end of this song

    This line is confusing. They’re either saying that the odds are 23:1 (95.8%) or 4:1 (80%) that you, the listener, can fall in love by the end of the song. I've listened to it without changing my love status enough times just to catch the lyrics to say that I'm sure, statistically speaking, that they’re wrong.
    Surveys have shown that the average couple will drop the L-word after 14 dates, and that on average they’ll manage two dates a week. If this song was on the upper end of popular and played, say, 3 times a day on a radio station, you could reasonably hear it 150 times between meeting someone and falling in love with them (meaning 99.3% of the time you hear the song you wouldn't have fallen in love). Then again, the odds of the song playing the instant that you fall in love would only be 0.63% on a given day (at three randomly spaced plays of 3:01 each). This is on the upper end, of course – only 80% of people say they fall in love at some point in their 20s, and 33% of people settle down with their first love, so realistically the numbers are way lower than that. There’s no way I’d take 23:1 odds that you’ll fall in love by the end of the song.

    Hit by the A-Train, crashed in an airplane/ I wouldn't recommend either one

    I wouldn't recommend either one either. Apparently in 2011 146 New Yorkers were hit by a Subway (we can pretend it was the A-line), with 47 of them dying. If you live in New York, your odds of Subway-ing to death are 0.00057% (about 51 times higher than getting hit by lightning – watch out!).

    Your chances of dying on a single airline flight on a major world airline are 0.000021%. Of course, most trips are round trips, but even if you were to take two round-trips a year your risk would only be 0.000085%. And that’s just with the average of all major airlines – the top half of airlines are four times less risky per flight, leading to the fun conclusion that taking two round-trip flights a year has pretty much exactly the same risk of death as from bees.

    Killed by a Great White or a meteorite/ I guess there ain't no way to go that’s fun

    Fatal shark attacks are actually ridiculously uncommon – in the United States the chance of getting killed by a shark is less than 0.0000004%. In fact, people in New York are bitten 10 times more each year by other people than by sharks. This is probably not something to worry about.

    Nobody has ever died by a meteorite. That isn't to say that they can’t be dangerous (that Russian one certainly injured a lot of people), but with only approximately 500 meteorites hitting the earth every year, it isn't likely something to ever worry about either. Though if it happened, it wouldn't be fun – BNL is right on that count.

    Odds are we gonna be alright for another night

    On average, 150,000 people die every day. This puts your odds of surviving until the end of the song at around 99.99999996% (much higher than falling in love by the end of the song). The odds of you being “alright for another night” (here I assume "alright" means “still alive”) are about 99.9979% on average.

    However, approximately two thirds of those daily deaths are age-related, and in industrialized countries the proportion of age-related deaths is up to 90%. If we factor that in, and you’re part of the young and hip demographic this blog strives to cater to, your odds of surviving another night are about 99.9998%.


    Odds of you dying by any cause mentioned in the song this year: ~0.0006%*
    Odds of you being alright for another night: ~99.9998%

    *Only if you live in New York

    Thursday, August 8, 2013

    Credit Card Math

    Credit cards are an important part of our society [citation needed], and come with an almost unlimited variety of options and perks between them. Some cards have low interest rates, others give you fancy rewards; some cards require you to have a high income, but others are free. The choices really are nearly limitless.

    One of my favorite perks offered by credit cards is the ability to get cash back as a fraction of the amount you spend using the card (most likely this is actually a clever ploy to get people to put lots of money on their cards in order to run up large amounts of interest, but we'll ignore that for now). Getting straight cash can be easier to deal with than travel rewards unless you happen to use the same Miles system, and provides you with a lovely sum of money to play with usually once a year.

    But not all cards are created equal. If you take a quick look at the terms and conditions of some of the major cash-back cards that are offered, you might get a graph that looks something like this (please note: Scotiabank's cards offered different rates for different purchases, such as groceries, gas, etc. As a result, they weren't included as it made direct unambiguous comparisons impossible.):

    Whoa. My mistake. I set the axes equal to each other, and it almost made it look like the cash you'd get back was very nearly insignificant in the scheme of things. Silly me, that can't possibly be true...

    Ok, whew, that's much better. A few things to note right off the bat:

    • The graph includes annual fees, which explains why some cards start off negative
    • The analysis assumes that the only important differences between cards are the cash back rewards and annual fees, and ignores differences in interest rates, maximum credit limits, minimum income requirements, etc.
    • At some point in the future, CIBC's thesaurus is likely to run out of cool sounding words to add on to credit card names
    The clear winner here is the Capital One card, which provides a free 1.0% cash back system which can be withdrawn from at any time, plus an additional 50% of the accrued cash back once a year (for an equivalent 1.5% cash back system). If we ignore it, though, there is actually a very neat transition between the different cards based on how much you are likely to spend each year:

    If you spend:

    $0-7,500: Get the TD Cash Back MasterCard. No annual fee and 0.75% cash back is a pretty decent deal, all in all. Take it and run! This is way better than its cousin, the TD Gold Elite Visa, which offers 1% but has a $79 annual fee. This range works out to credit card bills of less $625/month, and if you feel you pay more than that on average, why not try...

    $7,500-24,000: The CIBC Dividend Visa. This one also has no annual fee, but its pay structure is tiered (0.25% up to the first $1,500, 0.50% for the next $1,500, and 1% after that), so it takes a while to catch up to the TD card from before. This card is the most profitable for quite a range, though! In the interest of fairness, it is worth mentioning that the RBC Visa Cash Back card is very close and works out to only $0.25 less cash back a year over this range, as the card is a constant 1% reward but cost a $19 annual fee. Its rewards, however, are capped after $25,000 spending per year, so if you're unsure of your spending you're still better to stick with the CIBC card. And if you're going outside of that range anyway, you may as well consider...

    $24,000-35,300: The BMO CashBack World MasterCard. (Note how the card names get longer at higher price ranges?) This card offers an aggressive 1.25% cash back, but was offset by a $79 annual fee. If you feel like even that isn't enough to put on a card, go for either...

    $35,300-50,000: The CIBC Dividend Infinite or Dividend Unlimited World Elite Visa. (Seriously how ridiculous are these names?). These cards are both tied over this range, and both cards have identical tiered reward schemes and $79 annual fees. Unfortunately, the Dividend Infinite isn't all that infinite, and its rewards are capped after $50,000 of spending, at which point...

    $50,000-94,000: The Unlimited World Elite takes over solo in all its shining glory, until...

    $94,000 and beyond: The BMO CashBack catches right back up. It's able to do this because its rewards run at a higher rate than the highest tier of the Unlimited World Elite. After this, there's really no stopping it (apart from, of course, the aforementioned Capital One card, which is laughing at all these other cards from the finish line). 

    Really, though, if you're making enough money to be able to put $94,000 on a single credit card every year, you probably don't particularly care about which card offers you a handful of dollars more than another one.