What are the chances?

I'm working on a short story about probability, and how people react to extremely improbable events, specifically a coin which always comes up heads. Basic probability tells us that the chances that a coin will be tossed heads N times in a row goes down exponentially has N increases, but I wanted to get a better sense of what that really meant.

I wanted to know: how many times in a row does a coin have to come up heads for you to call it extremely improbable? I decided "extremely improbable" would mean, "If you flipped a coin every second for an entire lifetime, you'd only have a 50% chance of seeing it happen."

My first step was to determine the probability of seeing N heads flips in a row, given that you flipped M coins. I came up with a pair of mutually recursive equations which describe this. One gives the number of sequences of length M containing a subsequence of N heads results in a row, the other gives the number of sequences of length M which don't.

I'm too lazy to justify it here, but I verified it against a brute-force approach for M and N up to 15, and it works. Figuring out why it works is an exercise left to the reader.

I wrote a dynamic programming algorithm to compute this in Go, and with a little bit of work, I got my answer:

If you flip a coin every second for 108 years (a very generous lifetime), you have about a 50% chance of ever seeing the coin come up heads 31 times in a row. To get 10 headses in a row with 50% probability, you only need 1,421 flips (about 24 minutes at one flip per second) . To get 31 you need about 3.4 billion.

Only 31 flips. I think that's remarkable.

Renovated hjfreyer.com, pentris.net launched!

I've enjoyed maintaining Pentris over the past few years since I first wrote it. It's fun and it has a small following; it gets played a couple thousand times a month, has a bit over 50 unique visitors every day, and has made me about $45 in advertising revenue in 3 years (yeah, I haven't been trying that hard on this front). The fact that people keep coming back to play keeps me coming back to improve it now and then, and recently I decided that it deserves its own domain.

I'm happy to announce that http://www.pentris.net is the now the official place to fulfill all your Pentris-related needs! It even has a cool new logo:

Previously, Pentris was hosted on hjfreyer.com, which ran on Google Sites. Sites is pretty acceptable for hosting a simple personal page, but unfortunately I couldn't stay on Sites if I wanted to make a smooth transition from hjfreyer.com/pentris to pentris.net (Sites doesn't let you do 301 redirects). I had to remake my site from scratch and host it elsewhere. I'm glad I did, though; I turned a bland site with four sparse pages into a single page which looks pretty nice. Compare the old with the new.

Eagle-eyed readers may notice that I completely ripped off the design of about.me (e.g.). I did so because it's a good design. Show me an artist who isn't a thief, and I'll show you a web programmer who isn't lazy.

Check out the new sites and let me know if either of them cause you any trouble.

A thought on dreaming

A couple weeks ago I had lucid dreams a few nights in a row. Lucid dreaming is pretty cool, but blurring the line between sleep and waking life can be troubling. In the morning I would ask myself, "what's the difference between this world and that of my dreams?"

I decided that the key distinction is that in the real world, things tend to happen for explicable reasons. Much less so in dreams. Usually when awake you can reconstruct the cause-and-effect chain which led to an event, but in dreams they are often omitted, and in the midst of the dream we're cool with that.

Dreams are valuable because they drop us in hypothetical situations and let us see how we'd behave. How might you act if your best friend refused to talk to you for no reason? What if you married your ex? How would you survive a zombie apocalypse? We can only gain the insights these dreams give us because we're willing to put aside the question "why is this happening?"

But there's a problem with this distinction: in real life, things happens for no good reason all the time. Super-fit health nuts die of cancer at 30 while obese alcoholics live to 100. Millions have been brutally killed in war crimes ordered by dictators who die comfortably in their beds. Goodness is exploited and greed is rewarded and nobody has a good answer to the question "why?" To get by in this life, you have to live with leaving the question unanswered. You can either believe that there is no reason, or that there is some unknowable reason and hopefully someday you'll be let in on the secret.

So this leads to the obvious question: what if this life is just a dream? What if the real world is a place where everything happens for a good reason, and the reality we know is just a place where our minds can experiment with the question, "what if bad things happened to good people?" What if, to our waking selves, the random misfortunes that befall the good are as outlandish as flying humans, or talking animals, or accidentally getting on a nonstop bus to China? And what if our visions of Heaven and Hell are just distant memories of what the waking world is really like?