{"id":92,"date":"2008-07-19T01:07:21","date_gmt":"2008-07-19T06:07:21","guid":{"rendered":"http:\/\/www.moroha.net\/blog\/?p=92"},"modified":"2012-04-17T13:17:06","modified_gmt":"2012-04-17T18:17:06","slug":"how-to-get-92-heads-in-a-row","status":"publish","type":"post","link":"https:\/\/www.moroha.net\/blog\/archives\/92","title":{"rendered":"How to get 92 heads in a row"},"content":{"rendered":"<p>A couple of <a href=\"http:\/\/www.moroha.net\/blog\/?p=90\">posts<\/a> ago I talked about how laughably improbable it would be to get 92 heads in a row on a fair coin.  To sum up, the probability is:<br \/>\n<center>\\(\\displaystyle\\left(\\frac{1}{2}\\right)\\left(\\frac{1}{2}\\right)\\left(\\frac{1}{2}\\right)\\cdots\\left[\\text{92 times}\\right]\\cdots\\left(\\frac{1}{2}\\right)=2^{-92}=2.017\\times 10^{-28}\\)<\/center><\/p>\n<p>The probability of this happening is so abysmally low that you could flip coins your entire life and never expect to see this happen.  Or could you?  How many times <em>would<\/em> you need to flip a coin to see a reasonable chance of this happening?<\/p>\n<p>A pointless question?  Most certainly.  But trying to answer pointless questions that can be solved by math is one of the trademarks of a geek.  So a quick review of probability and statistics lead me to the <a href=\"http:\/\/www.aiaccess.net\/English\/Glossaries\/GlosMod\/e_gm_geometric.htm\">Geometric Distribution<\/a>, which gives the probability of an event occurring after a given number of trials.<br \/>\n<center>\\(\\displaystyle{P=p\\left( 1-p\\right)^{k-1}}\\)<\/center><br \/>\nHere <em>p<\/em> is the probability of the event occurring once in one trial, i.e. \\(2.017\\times 10^{-28}\\).  <em>k<\/em> is the number of trials, and <em>P<\/em> is the probability of the event occurring once within <em>k<\/em> trials.  However, this equation doesn&#8217;t quite give us the probability distribution we need.  This function will give us the probability of getting exactly one event (heads 92 times in a row) out of <em>k<\/em> trials (flipping a coin 92 times in a row <em>k<\/em> times).  We&#8217;re not interested in the probability of exactly one success, we&#8217;re interested in the probability of <em>one or more<\/em> successes.  For that, we need the related Cumulative Distribution Function.  Basically it&#8217;s the sum of the probabilities of 1, 2, 3,&#8230; up to <em>k<\/em> successes out of <em>k<\/em> trials.  It&#8217;s actually pretty easy to derive without performing sums for arbitrarily large values of <em>k<\/em>.  Since we want one or more successes, that means the only thing we don&#8217;t want is a failure for <em>every<\/em> trial.  The probability of a single failure is simply \\(1-p\\), so the probability of <em>k<\/em> failures is \\(\\left( 1-p\\right)^{k}\\). Since we want every possible combination except every trial a failure, we just subtract this from 1 (the sum of <em>all<\/em> possible combinations is of course equal to one).  This function comes out to be:<br \/>\n<center>\\(\\displaystyle{F=1- \\left( 1-p \\right)^k}\\)<\/center><br \/>\nChoosing a reasonable number for <em>F<\/em>, we&#8217;ll select 0.98.  Solving the above equation for <em>k<\/em> we get:<br \/>\n<center>\\(\\displaystyle{k=\\frac{\\text{ln}\\left( 1-F\\right)}{\\text{ln}\\left( 1-p\\right)}}\\)<\/center><\/p>\n<p>This equation is exact, but it has a big problem.  No normal calculator or computer is going to be able to calculate the answer because of the denominator.  The logarithm of one is zero, so the logarithm of a number very very close to one is a very very small number.  But no normal calculator is going to be able to handle \\(\\text{ln}\\left( 1-2^{-92}\\right)\\approx\\text{ln}\\left( 0.999999999999999999999999999798\\right)\\)<br \/>\n(Note I said no <em>normal<\/em> calculator.  I used <a href=\"http:\/\/en.wikipedia.org\/wiki\/Mathematica\">Mathematica<\/a> for this and it works fine.  But anything limited to double-precision arithmetic isn&#8217;t going to get you there.) Fortunately there is a convenient Taylor series expansion for \\(\\text{ln}\\left( 1-x\\right)\\).  It is<br \/>\n<center>\\(\\displaystyle{\\text{ln}\\left( 1-x\\right)=\\sum_{i=1}^{\\infty}\\frac{x^i}{i}}\\)<\/center><br \/>\nThe first term in the series will give more than sufficient precision in this case, so we have<br \/>\n<center>\\(\\displaystyle{k=-\\frac{\\text{ln}\\left( 1-F\\right)}{p}}\\)<\/center><br \/>\nThis tells us how many trials we we will need to to have a 98% confidence of getting 92 heads in a row, but it doesn&#8217;t tell us how many coin flips we will need.  Now a trial is defined as 92 coin flips, and if all 92 are heads it is a success, otherwise it is a failure.  However, we don&#8217;t need to do all 92 flips each time, as soon as we get our first tails, we already know that the trial is a failure and we can start over.  Since a fair coin is going to result in tails half of the time, then that means on average we will have two flips for every trial.  So if <em>f<\/em> is the total number of coin flips we will need to get a 98% confidence, then:<br \/>\n<center>\\(\\displaystyle{f=-\\frac{2\\;\\text{ln}\\left( 1-0.98\\right)}{2^{-92}}=3.874\\times 10^{28}}\\)<\/center><br \/>\nThis is a very very big number.  If we flipped a coin once a second, how long would it take us to get this number of flips?<br \/>\n<center>\\(\\displaystyle{3.874\\times 10^{28}\\,\\text{flips}\\left( \\frac{1\\;\\text{s}}{1\\;\\text{flip}}\\right)\\left( \\frac{1\\;\\text{yr}}{3.1557\\times 10^{7}\\;\\text{s}}\\right)=1.22\\times 10^{21}\\;\\text{yr}}\\)<\/center><br \/>\nAnd how long is this?  This is really, <em>really<\/em> long.  Astronomers estimate the current age of the universe to be \\(1.373\\times 10^{10}\\) years old.  That puts it as 100 billion times longer than the current age of the universe.  This is a feat that could only be pulled off by, say, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Minor_characters_from_The_Hitchhiker's_Guide_to_the_Galaxy#Wowbagger.2C_the_Infinitely_Prolonged\">Wowbagger, the Infinitely Prolonged<\/a>.  According to <a href=\"http:\/\/en.wikipedia.org\/wiki\/Heat_death_of_the_universe#White_dwarfs_and_Black_dwarfs_fall_or_are_flung_from_orbits:_1019years\">this fascinating article<\/a> on the eventual heat death of the universe, at this point there will be no matter left in the universe but white and black dwarfs (and black holes, but I don&#8217;t know if they&#8217;re considered to be matter within our universe or not), and they will be flung from their orbits due to gravitational radiation.<\/p>\n<p>So is all lost?  Is there no way to get 92 heads in a row?  For all practical purposes, yes, there is no way.  As for <em>impractical<\/em> purposes though, in a subsequent post I&#8217;ll detail a way that we could accomplish it long before the death of the universe using a scheme that in all reality would only make sense in a Douglas Adams&#8217; universe.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of posts ago I talked about how laughably improbable it would be to get 92 heads in a row on a fair coin. To sum up, the probability is: The probability of this happening is so abysmally low &hellip; <a href=\"https:\/\/www.moroha.net\/blog\/archives\/92\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/www.moroha.net\/blog\/wp-json\/wp\/v2\/posts\/92"}],"collection":[{"href":"https:\/\/www.moroha.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.moroha.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.moroha.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.moroha.net\/blog\/wp-json\/wp\/v2\/comments?post=92"}],"version-history":[{"count":27,"href":"https:\/\/www.moroha.net\/blog\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"predecessor-version":[{"id":591,"href":"https:\/\/www.moroha.net\/blog\/wp-json\/wp\/v2\/posts\/92\/revisions\/591"}],"wp:attachment":[{"href":"https:\/\/www.moroha.net\/blog\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.moroha.net\/blog\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.moroha.net\/blog\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}