Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Should I parse it as tossing the same coin 10 times, or choosing from the jar 10 times?


Good question, and one that sometimes comes up when I ask it in interviews. You are tossing the same coin 10 times.


0.753?

A the beginning, there's a 1/1000 chance that you pick a double-headed, and a 999/1000 chance you pick a fair coin.

A fair coin would act the way you've observed 1/1024 times. A double-headed coin would act that way 100% of the time.

(This is where I get fuzzy): Given what you've observed, there is a (1000+1024)/1024 = 0.506 chance that the coin is double-headed. There is a 0.494 chance that it's fair.

A double-headed coin would come up heads next 100% of the time. A fair coin would come up heads 50% of the time. So, 0.506 x 1 + 0.494 x 0.5 = 0.753.

How far off am I?


Your .506 is right but the arithmetic problem that you set equal to it is wrong. I think you meant to type 1024/(1024+1000). (BTW, it should be 1024/(1024+999) ).


Close enough for beta. We'll refine after user testing. (Guess my specialty!)


This is a fun question. Can I look at the coin's two sides? If not...I assume you now have to start applying statistical tests (given that a fair coin will only do this once out of 1024 times, what are the chances I've got one of those 999 coins vs the 1/1000 chance that I picked the double headed coin?) or is there some simplifying assumption I'm missing.

Anyway--assume I think all that aloud in an interview. What does that tell you about the candidate?


>Can I look at the coin's two sides?

I would give points for just asking that question, because many people bound by conventional thinking wouldn't dare to ask it, accepting default assumption that you can't. I'm not saying this says anything about your ability to solve the problem, but asking the question is a good sign of a supple mind.


You can only see the result of the flips, you can't examine the coin. Yes, it comes down to estimating the probability of having a biased coin given that you have seen it come up heads ten times in a row.


0.5005?


That's what I got.

There's a .999 chance you have a fair coin and a .001 chance you have the rigged coin.

(0.999 * 0.5) + (0.001 * 1) = 0.5005.

Seems too simple, but a coin is a coin, right?


Ask yourself a question: can you use the data (the 10 coin tosses) to update the probability of the current coin being two-headed?


I wouldn't use the data. The coin hasn't changed since I picked it out of the jar. If I flip it 1, 10, or 10e100 times, the coin would still be the same coin.

So figure the p(heads) for the coin and ignore the previous history. Overthinking it is why this makes a good FizzBuzz problem.


An example that should show this approach is wrong:

Suppose that the jar contains 500 double-head coins and 500 double-tail coins. You pull a coin from the jar, flip it 10 times, and get 10 heads. What is the probability it will come up heads next time?


That seems like a completely different problem to me, since all randomness is out of the system the moment you see the first flip.


OK, so now imagine that there are 1000000 double-headed coins, 1000000 double-tailed coins, and one fair coin. Now (1) there's still (potentially) randomness present, so it's not "completely different" from the original problem, but (2) the ignore-the-data approach gives an obviously wrong answer whereas using the data gives a believable answer.


Let's consider that it might be a fair coin, or it might be a double-headed coin.

Let's also say that every time you flip the coin and it comes up tails, you win $5. And every time you flip the coin and it comes up heads, you lose $1.

Clearly, this would be a great game to have the opportunity to play, if the coin is fair. Every time you flip you either win $5 or lose $1, so your profit, on average, is $4 per flip.

You've flipped it 10 times so far, and it's come up heads every time, and you've lost $10.

After you're $10, $100, $1000, or $10e100 in the red, without ever seeing a win, when do you change your mind about playing this game?


You are getting downvotes because you didn't follow Bayesian reasoning, but there is some justification for your instincts here http://www.stat.columbia.edu/~gelman/research/unpublished/ph...


Yes, it's still the same coin, but you don't know which coin you got. You know that you got 10 consecutive heads though. How improbable this is if you got a fair coin? How probable this is with the double-head coin? This is the data you can use to update the probability.


So if you flipped the coin twice, once it was tails, and once it was heads... you'd ignore that info? Or look at it another way, if you flipped it a million times and it always came up heads...




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: