Be Excellent To Each Other

And, you know, party on. Dude.

All times are UTC [ DST ]




Reply to topic  [ 57 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 17:23 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Assuming a fair coin and no 'black swan' events, what is the probability of flipping 100 heads in a row?


(Without having a Google around or anything like that, just have a guess. The answer is in the spoiler text below.)

I have been reading up quite a bit recently on probability, randomness, standard deviations and all that jazz. (Partly because I find it interesting, but mostly because it's relevant to my ongoing online gambling shenanigans where all the games are random.)

Recently, on a set of gambling forums I was trying to explain how a truly random slot machine could display a percentage payout even though it was random.

The objectors were basically saying 'It can't be guaranteed to reach a percentage if it's random!', I referred them to the law of large numbers and specifically to coin flips, to be told, 'But I could flip a coin 100 times and they could all be heads, it's not very likely, but it could happen! So a random slot machine might never reach its target percentage so they shouldn't be allowed to display it.'

ZOMG Spoiler! Click here to view!
1 in 1,267,650,600,228,229,401,496,703,205,376

In the US number naming system, it is one nonillion, 267 octillion, 650 septillion, 600 sextillion, 228 quintillion, 229 quadrillion, 401 trillion, 496 billion, 703 million, 205 thousand, 376.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 18:16 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
AtrocityExhibition wrote:
Assuming a fair coin and no 'black swan' events, what is the probability of flipping 100 heads in a row?

0.5^100.

Assuming you mean "in 100 flips". If you rephrase the question to "how many flips do you need to make to have a reasonable chance of flipping 100 heads in a row at any point in the sequence" the maths becomes more interesting. Derren Brown exploits this to great effect on one of his shows to show him, with no video editing, flipping 20 (IIRC) heads in a row... after 12 hours of filming flips.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 18:29 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Doctor Glyndwr wrote:
0.5^100.


In that case my number is wrong then, what is 0.5^100 expressed as a '1 in x' chance of?


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 18:31 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
AtrocityExhibition wrote:
Doctor Glyndwr wrote:
0.5^100.


In that case my number is wrong then, what is 0.5^100 expressed as a '1 in x' chance of?

http://www.google.co.uk/search?q=1/(0.5%5E100)


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 18:46 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
AtrocityExhibition wrote:
Recently, on a set of gambling forums I was trying to explain how a truly random slot machine could display a percentage payout even though it was random.

Gamblers in "not actually understanding statistics" shocker.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 18:52 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Doctor Glyndwr wrote:
Gamblers in "not actually understanding statistics" shocker.


As an expected return over time (known as RTP, Return To Player), a random machine can display a percentage payout.

What people generally fail to understand is that a random machine will not AIM for a percentage, and that it's never 'due' to pay, but that given enough hundreds of thousands or millions of spins, from a truly random paytable, you can establish an RTP with some certainty.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 18:54 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Doctor Glyndwr wrote:
Derren Brown exploits this to great effect on one of his shows to show him, with no video editing, flipping 20 (IIRC) heads in a row... after 12 hours of filming flips.


The odds of that are 1 in over two million.

Flipping 10 is what he did, as that's 1 in 1024.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 18:55 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
AtrocityExhibition wrote:
What people generally fail to understand is that a random machine will not AIM for a percentage, and that it's never 'due' to pay, but that given enough hundreds of thousands or millions of spins, from a truly random paytable, you can establish an RTP with some certainty.
That seems intuitively obvious to me, and the concept of an entire forum full of hobbyist gamblers who don't get it... well, I find that either terrifying, or motivating to buy some shares in companies that sell these people gambling services.

Is it really truly random? What's the entropy pool?


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 18:56 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
AtrocityExhibition wrote:
The odds of that are 1 in over two million.

Flipping 10 is what he did, as that's 1 in 1024.
Ah, you are correct, but note that his odds of succeeding weren't 1 in 1024. They were much higher.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 18:59 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Doctor Glyndwr wrote:
Ah, you are correct, but note that his odds of succeeding weren't 1 in 1024. They were much higher.


About 66% for success and 34% for failure I think.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 19:02 
User avatar
Comfortably Dumb

Joined: 30th Mar, 2008
Posts: 12034
Location: Sunny Stoke
Doctor Glyndwr wrote:
AtrocityExhibition wrote:
What people generally fail to understand is that a random machine will not AIM for a percentage, and that it's never 'due' to pay, but that given enough hundreds of thousands or millions of spins, from a truly random paytable, you can establish an RTP with some certainty.
That seems intuitively obvious to me, and the concept of an entire forum full of hobbyist gamblers who don't get it... well, I find that either terrifying, or motivating to buy some shares in companies that sell these people gambling services.


On the Microgaming slots, each game shows a 'temperature meter' before you play it - the higher the temperature, the length of time since it last paid a jackpot. Some folk will see this and think it's due a jackpot, despite the casino stating that each spin is random and previous spins have no bearing on the next one. They do point out that the meter is just a guide too.

_________________
Consolemad | Under Logic
Curse, the day is long
Realise you don't belong


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 19:05 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
devilman wrote:
Some folk will see this and think it's due a jackpot
Seriously? This is GCSE-level statistics we are discussion here.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 19:11 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Doctor Glyndwr wrote:
Is it really truly random? What's the entropy pool?


The RNGs are externally audited and approved by the appropriate regulators in the various jurisdictions, and AFAIK no one has ever worked them out.

At a basic level the idea is that the game has perhaps one million results from any given spin of the reels to choose from, when the player presses SPIN the game calls a number from the RNG, references that to a result on the paytable, and displays the result.

Quote:
That seems intuitively obvious to me, and the concept of an entire forum full of hobbyist gamblers who don't get it... well, I find that either terrifying, or motivating to buy some shares in companies that sell these people gambling services.


Microgaming (the biggest online casino software provider in the world) are headquartered here on the IOM, given their premises, I think it's safe to say there's some good money in the business.

And yes, ignorance amongst players can be amazing. Many of them simply do not understand the basic concepts that I referenced in my original post, and get cleaned out regularly as a result. (Another concept that is totally lost on many players is 'variance', whereby random machines with identical RTPs can have massively different play profiles.)


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 19:16 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
devilman wrote:
On the Microgaming slots, each game shows a 'temperature meter' before you play it - the higher the temperature, the length of time since it last paid a jackpot. Some folk will see this and think it's due a jackpot, despite the casino stating that each spin is random and previous spins have no bearing on the next one. They do point out that the meter is just a guide too.


Yeah I think that's a really cheeky addition on Microgaming's part to be honest. Yes they put the disclaimer next to the 'thermometer', but then again, why have it there at all?

Ignorance is rife, and that sort of thing doesn't help.

Over at one set of forums (what you would say are probably one of the 'premiere' set of gambling forums in the world), someone posted a thread with a load of screenshots of them having a really good run at one casino and cashing out with a serious profit.

One of the replies was 'Well I was going to deposit there and play but I'd better give it a few months now' - and I was just like 'That really, really isn't how random numbers work dude.'


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 19:24 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
AtrocityExhibition wrote:
The RNGs are externally audited and approved by the appropriate regulators in the various jurisdictions, and AFAIK no one has ever worked them out.

At a basic level the idea is that the game has perhaps one million results from any given spin of the reels to choose from, when the player presses SPIN the game calls a number from the RNG, references that to a result on the paytable, and displays the result.
Sure, but computers cannot calculate true random numbers, not without help. I'm not sure if hardware random number generators are too expensive to fit to humdrum slot machines though.

Edit -- I'm an idiot, there are several cost-efficient solutions on that page alone. I wonder what the gambling guys use.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 19:35 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Doctor Glyndwr wrote:
I'm not sure if hardware random number generators are too expensive to fit to humdrum slot machines though.


These are not humdrum slot machines DrG, Microgaming alone pack multiple geographically diverse resilient datacentres that would make any techy weep tears of joy.

Their servers go down, the players can't play, and they can't make any money - which is why they keep that shit up 24/7/365. Maintenance windows are for wimps.....

You're talking about a multi-billion dollar industry* here, I'm pretty sure they've got the RNGs sorted :)

Sometimes they even cheat too - not Microgaming I should add, but some software providers have been caught out cheating beyond all mathematical doubt.

http://www.casinomeister.com/forums/com ... ating.html

There is a school of thought that says the reason Facebook is being valued at such astronomical figures is there's an expectation that the USA is going to legalize online gambling in some form in the near future, repealing or amending the UIGEA.

http://en.wikipedia.org/wiki/Unlawful_I ... ct_of_2006

Facebook already has all the casino software built into it, but at the moment, it's only play money.....


* I use the term 'industry' advisedly since they don't actually produce anything other than misery.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 20:00 
User avatar
Sleepyhead

Joined: 30th Mar, 2008
Posts: 27347
Location: Kidbrooke
AtrocityExhibition wrote:
devilman wrote:
On the Microgaming slots, each game shows a 'temperature meter' before you play it - the higher the temperature, the length of time since it last paid a jackpot. Some folk will see this and think it's due a jackpot, despite the casino stating that each spin is random and previous spins have no bearing on the next one. They do point out that the meter is just a guide too.


Yeah I think that's a really cheeky addition on Microgaming's part to be honest. Yes they put the disclaimer next to the 'thermometer', but then again, why have it there at all?

Ignorance is rife, and that sort of thing doesn't help.


You answered your own question. It's the same reason roulette tables have a record of the last X spins next to them; to fool suckers.

I was playing a table in Vegas where the entire board 15 or so numbers were black (it had hit black that many times in a row). People were just walking past, seeing that, and throwing hundreds of dollars on red. Eventually it hit red, of course, but not before absolutely rinsing a fortune out of schmucks.

_________________
We are young despite the years
We are concern
We are hope, despite the times


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sat Apr 14, 2012 20:08 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Curiosity wrote:
You answered your own question. It's the same reason roulette tables have a record of the last X spins next to them; to fool suckers.

I was playing a table in Vegas where the entire board 15 or so numbers were black (it had hit black that many times in a row). People were just walking past, seeing that, and throwing hundreds of dollars on red. Eventually it hit red, of course, but not before absolutely rinsing a fortune out of schmucks.


Indeed!

It's weird though, if you're gambling your own money at these institutions, surely you'd want to have at least some modicum of understanding as to how it all works?

http://en.wikipedia.org/wiki/Gambler%27s_fallacy

Monte Carlo Casino

The most famous example happened in a Monte Carlo Casino in the summer of 1913, when the ball fell in black 26 times in a row, an extremely uncommon occurrence (but no more or less common than any of the other 67,108,863 sequences of 26 balls, neglecting the 0 slot on the wheel), and gamblers lost millions of francs betting against black after the black streak happened. Gamblers reasoned incorrectly that the streak was causing an "imbalance" in the randomness of the wheel, and that it had to be followed by a long streak of red.[1]


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Sun Apr 15, 2012 1:23 
User avatar
Goth

Joined: 31st Mar, 2008
Posts: 3742
This sort of thing was covered in Carl Sagan's Demon Haunted World. Dealing with things like winning streaks. It was quite interesting when considering some 'great commanders' whose number of victories actually seemed to be about the statistical average for two equally matched sides meeting. But yes, few people really understand probability.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 8:26 
User avatar
Gogmagog

Joined: 30th Mar, 2008
Posts: 48823
Location: Cheshire
When the machines say "70%", it's easier to remember that for every £1 you put in, 30p drops into the owner's box.

_________________
Mr Chris wrote:
MaliA isn't just the best thing on the internet - he's the best thing ever.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 9:30 
User avatar
Rude Belittler

Joined: 30th Mar, 2008
Posts: 5016
If a roulette wheel hit black 26 times in a row, I'd bet black. But only if I was playing roulette, and I would only bet a normal amount.

Although, roulette is a mugs game anyway.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 20:45 
User avatar
Slightly Brackish

Joined: 28th Jan, 2011
Posts: 1198
I've only skimmed since the first few posts so please forgive any repetition, but surely you need to give us a time scale for a meaningful answer. If you simply pick up a coin and flip it until failure then the Doc's answer is correct; however if we are looking for a chain of 100 within a sample of any size we like and can simulate the coin flips electronically then we would get a sample size so close to infinite that the probability of a chain of 100 heads was virtually 1 (an extreme extension of the Derren Brown thing alluded to already).

And yes, of course gamblers don't understand odds/probabilities... if they did then they wouldn't be gamblers, and they enjoy it too much to dare think about such things for fear of common sense kicking in and ruining their fun.

_________________
Current games: Luxor 2, Boom Boom Rocket


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 21:01 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
MaliA wrote:
When the machines say "70%", it's easier to remember that for every £1 you put in, 30p drops into the owner's box.


Depends what the machines are, when it comes to compensated machines, (AWPs i.e. the pub fruit machine), it's possible for a player to make a 100%+ return consistently pretty much indefinitely. (Which is exactly what I do, even though these machines are generally set to just 74-76% payouts.)

Only playing certain machines in certain ways, obviously.

Random games of course, there's no way to beat, even at expected RTPs as high as 99%, although if you're clever about what bonus offers you take at online casinos, you can certainly get to even odds of getting your money back quite a lot of the time.

I look at AWPs as my 'money making' gambling play, and online slots as my fun (I expect to lose on them in the long term).


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 21:03 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Alberto wrote:
I've only skimmed since the first few posts so please forgive any repetition, but surely you need to give us a time scale for a meaningful answer. If you simply pick up a coin and flip it until failure then the Doc's answer is correct; however if we are looking for a chain of 100 within a sample of any size we like and can simulate the coin flips electronically then we would get a sample size so close to infinite that the probability of a chain of 100 heads was virtually 1 (an extreme extension of the Derren Brown thing alluded to already).


I was talking about picking up a coin and flipping 100 heads on the first 100 flips.

Yes if you simulate out to infinity you'd get 100 in a row eventually, although at 60 flips per second I suspect the end of universe would come about before it actually occurred.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 21:14 
User avatar
Comfortably Dumb

Joined: 30th Mar, 2008
Posts: 12034
Location: Sunny Stoke
AtrocityExhibition wrote:
Yes if you simulate out to infinity you'd get 100 in a row eventually, although at 60 flips per second I suspect the end of universe would come about before it actually occurred.


Always obsessed with 60fps...

_________________
Consolemad | Under Logic
Curse, the day is long
Realise you don't belong


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 22:02 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
devilman wrote:
AtrocityExhibition wrote:
Yes if you simulate out to infinity you'd get 100 in a row eventually, although at 60 flips per second I suspect the end of universe would come about before it actually occurred.


Always obsessed with 60fps...


You're such a POTW whore.

Having done a BeexWeex presentation now, I realise how this shit works.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 22:23 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
AtrocityExhibition wrote:
60 flips per second

With an electric simulation, even a wimpy CPU will be able to do a millions of flips a second.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 22:33 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Science us then, Doc.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 22:35 
User avatar
baron of techno

Joined: 30th Mar, 2008
Posts: 24136
Location: fife
In the UK it's 50fps, always has been.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 22:44 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
Grim... wrote:
Science us then, Doc.

I'll need to write some test code. Tomorrow.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 22:45 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Do you have a monster server hanging around that you could stick it on?

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 22:54 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
No, but it won't matter -- it won't get anywhere near 0.5^100 in practical lengths of time. I think. I'm curious about just how long it would take for, say, a 10% chance of generating 100H in a row though.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 23:11 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Doctor Glyndwr wrote:
AtrocityExhibition wrote:
60 flips per second

With an electric simulation, even a wimpy CPU will be able to do a millions of flips a second.


Dammit I know that! I was just trying to illustrate the point that you could flip a virtual coin every second from now 'until the end of time' as it were, and never see 100 heads in a row.

Once per second just sounded like a nice way to get the point over as it's a metronome that everyone can relate to. If you say 'one million per second' then you're getting into abstract numbers again that human beings don't instinctively process well.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 23:13 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Doctor Glyndwr wrote:
No, but it won't matter -- it won't get anywhere near 0.5^100 in practical lengths of time. I think. I'm curious about just how long it would take for, say, a 10% chance of generating 100H in a row though.


Isn't 1 in 0.5^100 such a vanishingly small probability that it will basically never happen?

I've seen it suggested elsewhere that you could get every single computer on the planet chucking 100% of their CPU resources at flipping coins and none of them will turn up 100 heads in a row before our sun goes supernova.


Top
 Profile  
 
 Post subject: Brain teaser maths question
PostPosted: Mon Apr 16, 2012 23:25 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
If my derivation is correct, the probability of getting n heads in a row from t flips is given by the formula below. I'll check it over in the morning.


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 7:27 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
AtrocityExhibition wrote:
Once per second just sounded like a nice way to get the point over as it's a metronome that everyone can relate to.

I guess that's why we got confused when you said sixty times per *second*.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 10:18 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
My derivation above is wrong; according to my working, the probability p of getting n heads in a row in t tosses is given by:

Code:
p = ( 2^(t-n) * (t-n+1) ) / ( 2^t )


It's the 2^(t-n) on the top that's important.

That gives a probability, p, of 7.89 * 10^-9. 1,000,000,000 coin flips in a single threaded Java program (see below) takes 23 seconds.

For a probability of 0.1 (i.e. a 10% chance of getting 100 heads in a row), we need to do 1.267*10^29 flips. That will take my Java program around 2.92 * 10^21 seconds, or about 10^14 years -- i.e. 100,000 billion years. That's a lot, but it's nowhere near the heat death of the universe time frame (which is about 10^100 years). I could speed it up by throwing more hardware at it -- one of our big multicore DB servers has about 100x to 150x as much grunt as this laptop, for example. But obviously that only brings it down to 10^12 years or so.

However, the numbers for smaller numbers of heads are more tractable than you might think, because of the (2^(n-t)) factor in the numerator. To get 20 heads, for example, took the following numbers of flips on a few successive runs:

1037833, 3561129, 3362374, 6192144, 3523847

None of these took longer than a second.

Trying to get 40 heads, I managed instead (in successive runs of a billion flips) a max count of 29 heads, 28 heads, 30 heads.

Here's the Java:
ZOMG Spoiler! Click here to view!
Code:
package foo;

import java.util.Date;
import java.util.Random;

public class CoinToss {

   
   
   private Random rng;
   private long maxCount;
   
   
   public CoinToss(long maxCount) {
      rng = new Random();
      this.maxCount = maxCount;
   }
   
   public void go(int numberOfHeadsToGet) {
      long startTime = new Date().getTime();
      long count=0;
      int headsInARow=0;
      int maxHeadsInARow=0;
      
      while (headsInARow < numberOfHeadsToGet && count<maxCount) {
         if (rng.nextInt(2) == 1) {
            headsInARow++;
         } else {
            if (headsInARow > maxHeadsInARow)
               maxHeadsInARow = headsInARow;
            headsInARow=0;
         }
         count++;
      }
      
      
      long endTime = new Date().getTime();
      System.out.println("I ran for "+((endTime-startTime)/1000)+" seconds");
      System.out.println("I did "+count+" flips");
      if (headsInARow == numberOfHeadsToGet)
         System.out.println("**MISSION ACCOMPLISHED**");
      else
         System.out.println("I had "+maxHeadsInARow+" heads in a row");
         
   }
   
   /**
    * @param args
    */
   public static void main(String[] args) {
      CoinToss ct = new CoinToss(1000000000);
      ct.go(10);
   }

}


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 10:36 
User avatar
UltraMod

Joined: 27th Mar, 2008
Posts: 55717
Location: California
You fucking lunatic.

_________________
I am currently under construction.
Thank you for your patience.


Image


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 10:36 
User avatar
Legendary Boogeyman

Joined: 22nd Dec, 2010
Posts: 8175
Doctor Glyndwr wrote:
flipping 20 (IIRC) heads in a row... after 12 hours of filming flips.

Like the time he correctly 'predicted' 5 winning horses in a race, which looked incredibly impressive until he revealed he'd given different bets to different people to cover the full permutation of results, and had just showed the punter who'd been given the correct sequence.

_________________
Mr Kissyfur wrote:
Pretty much everyone agrees with Gnomes, really, it's just some are too right on to admit it. :)


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 10:38 
User avatar
Gogmagog

Joined: 30th Mar, 2008
Posts: 48823
Location: Cheshire
ElephantBanjoGnome wrote:
Doctor Glyndwr wrote:
flipping 20 (IIRC) heads in a row... after 12 hours of filming flips.

Like the time he correctly 'predicted' 5 winning horses in a race, which looked incredibly impressive until he revealed he'd given different bets to different people to cover the full permutation of results, and had just showed the punter who'd been given the correct sequence.


One can't help but feel the admission was somewhat the point of the exercise.

_________________
Mr Chris wrote:
MaliA isn't just the best thing on the internet - he's the best thing ever.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 10:41 
User avatar
Legendary Boogeyman

Joined: 22nd Dec, 2010
Posts: 8175
Doctor Glyndwr wrote:
(which is about 10^100 years)

Googol :D

I went to Festival of the Spoken Nerd last week, which was pretty awesome and featured Robin Ince who spent 20 minutes going on about Richard Feynman.

Anyway the Helen Arney lady sang on a song on a uke about Googolplexes. Fun times :hat:

Quote:
One can't help but feel the admission was somewhat the point of the exercise.


Well duh.

_________________
Mr Kissyfur wrote:
Pretty much everyone agrees with Gnomes, really, it's just some are too right on to admit it. :)


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 10:48 
User avatar
Excellent Member

Joined: 30th Mar, 2008
Posts: 5924
Location: Stockport - The Jewel in the Ring
ElephantBanjoGnome wrote:
I went to Festival of the Spoken Nerd last week, which was pretty awesome and featured Robin Ince who spent 20 minutes going on about Richard Feynman.


Yay!

Quote:
Anyway the Helen Arney lady sang on a song on a uke about Googolplexes. Fun times :hat:


Argh.

_________________
Mint To Be Stationery - Looking for a Secret Santa gift? Try our online shops at Mint To Be.

Book me in the Face | Tweet me. Tweet me like a British nanny.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 10:58 
User avatar
Legendary Boogeyman

Joined: 22nd Dec, 2010
Posts: 8175
Theme of the song had the audience singing out zeros as the chorus. Then she went on to sing that if every individual cell in your body, multiplied against the entire human race, sang out 3 zeros per second since the beginning of time, we'd only have sung out 10^64 zeros by now.

_________________
Mr Kissyfur wrote:
Pretty much everyone agrees with Gnomes, really, it's just some are too right on to admit it. :)


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 11:05 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
ElephantBanjoGnome wrote:
Doctor Glyndwr wrote:
flipping 20 (IIRC) heads in a row... after 12 hours of filming flips.

Like the time he correctly 'predicted' 5 winning horses in a race, which looked incredibly impressive until he revealed he'd given different bets to different people to cover the full permutation of results, and had just showed the punter who'd been given the correct sequence.

Well, yeah. That's the same episode, so it's no coincidence the principle is the same!


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 11:05 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
myp wrote:
You fucking lunatic.

*bows*


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 12:36 
User avatar
UltraMod

Joined: 27th Mar, 2008
Posts: 55717
Location: California
Doctor Glyndwr wrote:
myp wrote:
You fucking lunatic.

*bows*

I'm glad it was taken as the compliment it was intended. ;)

_________________
I am currently under construction.
Thank you for your patience.


Image


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 13:19 
User avatar
Sitting balls-back folder

Joined: 30th Mar, 2008
Posts: 10138
Doctor Glyndwr wrote:
For a probability of 0.1 (i.e. a 10% chance of getting 100 heads in a row), we need to do 1.267*10^29 flips. That will take my Java program around 2.92 * 10^21 seconds, or about 10^14 years -- i.e. 100,000 billion years. That's a lot, but then it's written in Java.


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 20:42 
User avatar
Slightly Brackish

Joined: 28th Jan, 2011
Posts: 1198
I'm doing it with a 10p. So far my best is 7.

_________________
Current games: Luxor 2, Boom Boom Rocket


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 20:51 
User avatar
Hello Hello Hello

Joined: 11th May, 2008
Posts: 13386
Doctor Glyndwr wrote:
My derivation above is wrong; according to my working, the probability p of getting n heads in a row in t tosses is given by:

Code:
p = ( 2^(t-n) * (t-n+1) ) / ( 2^t )


It's the 2^(t-n) on the top that's important.

That gives a probability, p, of 7.89 * 10^-9. 1,000,000,000 coin flips in a single threaded Java program (see below) takes 23 seconds.

For a probability of 0.1 (i.e. a 10% chance of getting 100 heads in a row), we need to do 1.267*10^29 flips. That will take my Java program around 2.92 * 10^21 seconds, or about 10^14 years -- i.e. 100,000 billion years. That's a lot, but it's nowhere near the heat death of the universe time frame (which is about 10^100 years). I could speed it up by throwing more hardware at it -- one of our big multicore DB servers has about 100x to 150x as much grunt as this laptop, for example. But obviously that only brings it down to 10^12 years or so.

However, the numbers for smaller numbers of heads are more tractable than you might think, because of the (2^(n-t)) factor in the numerator. To get 20 heads, for example, took the following numbers of flips on a few successive runs:

1037833, 3561129, 3362374, 6192144, 3523847

None of these took longer than a second.

Trying to get 40 heads, I managed instead (in successive runs of a billion flips) a max count of 29 heads, 28 heads, 30 heads.

Here's the Java:
ZOMG Spoiler! Click here to view!
Code:
package foo;

import java.util.Date;
import java.util.Random;

public class CoinToss {

   
   
   private Random rng;
   private long maxCount;
   
   
   public CoinToss(long maxCount) {
      rng = new Random();
      this.maxCount = maxCount;
   }
   
   public void go(int numberOfHeadsToGet) {
      long startTime = new Date().getTime();
      long count=0;
      int headsInARow=0;
      int maxHeadsInARow=0;
      
      while (headsInARow < numberOfHeadsToGet && count<maxCount) {
         if (rng.nextInt(2) == 1) {
            headsInARow++;
         } else {
            if (headsInARow > maxHeadsInARow)
               maxHeadsInARow = headsInARow;
            headsInARow=0;
         }
         count++;
      }
      
      
      long endTime = new Date().getTime();
      System.out.println("I ran for "+((endTime-startTime)/1000)+" seconds");
      System.out.println("I did "+count+" flips");
      if (headsInARow == numberOfHeadsToGet)
         System.out.println("**MISSION ACCOMPLISHED**");
      else
         System.out.println("I had "+maxHeadsInARow+" heads in a row");
         
   }
   
   /**
    * @param args
    */
   public static void main(String[] args) {
      CoinToss ct = new CoinToss(1000000000);
      ct.go(10);
   }

}


Kudos DrG :)

So it's 100,000 billion years to get to a 0.1 probability of seeing 100 heads, so to get to 0.5 (i.e. 50/50 chance it's happened) we are going to be getting on for the end of time as we know it?


Top
 Profile  
 
 Post subject: Re: Brain teaser maths question
PostPosted: Tue Apr 17, 2012 22:14 
User avatar
Gogmagog

Joined: 30th Mar, 2008
Posts: 48823
Location: Cheshire
Not "the end of time as we know it" as there's relativistic effects to consider, and when you reach the end of timespace you appear at the other end straight away.

_________________
Mr Chris wrote:
MaliA isn't just the best thing on the internet - he's the best thing ever.


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 57 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Columbo and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search within this thread:
You are using the 'Ted' forum. Bill doesn't really exist any more. Bogus!
Want to help out with the hosting / advertising costs? That's very nice of you.
Are you on a mobile phone? Try http://beex.co.uk/m/
RIP, Owen. RIP, MrC. RIP, Dimmers.

Powered by a very Grim... version of phpBB © 2000, 2002, 2005, 2007 phpBB Group.