I'm working through Stanford's  on Probability for Computer Scientists, and on #15 there's an extra credit question I can't explain:        Consider a game that uses a generator which produces independent random integers between 1 and 100 inclusive. The game starts with a sum $S = 0$. The first player adds random numbers from the generator to $S$ until $S &gt; 100$ and records her last random number as $x$. The second player continues adding random numbers from the generator to $S$ until $S &gt; 200$ and records her last random number as $y$. The player with the highest number wins, i.e. if $y &gt; x$ the second player wins. Is this fair? Write a program to simulate 100,000 games. What is the probability estimate, based on your simulations, that the second player wins? Give your answer rounded to 3 places behind the decimal. For extra credit, calculate the exact probability (without sampling).      By creating a Python script to simulate 100,000 games, the probability of the second player winning hovers around $0.532$. Yet, I suspected it to be $0.495$ since each players' last number could be any number from $1$ to $100$ since $S \leq 100$ is met to allow them to keep generating numbers. The same goes for player two and $S \leq 200$. Since each number seems equally likely, I found:  $$P(y &gt; x) = \frac{99 \cdot 100}{2} \cdot \frac{1}{100^2} = 0.495$$  But this is definitely not correct as the simulation shows. Where is the problem in my analysis? I made sure I used a uniform distribution for generating numbers in my simulation.
123365
Consider a game that uses a generator which produces independent random integers between 1 and 100 inclusive. The game starts with a sum S = 0. The first player adds random numbers from the generator to S until S > 100 and records her last random number 'x'. The second player, continues adding random numbers from the generator to S until S > 200 and records her last random number 'y'. The player with the highest number wins, i.e. if y > x the second player wins. Is this game fair? Write a program to simulate 100,000 games. What is the probability estimate, based on your simulations, that the second player wins? Give your answer rounded to 3 places behind the decimal. For extra credit, calculate the exact probability (without sampling).     import random  CONST_TIMES = 100000 CONST_SMALL = 100 CONST_LARGE = 200  def playGame():     s = 0     while s &lt;= CONST_SMALL:          x = random.randint(1, CONST_SMALL)         s = s + x;     while s &lt;= CONST_LARGE:         y = random.randint(1, CONST_SMALL)         s = s + y     if x &lt; y:         return 's'     elif x == y:         return 'm'     else:         return 'f'  fst = sec = 0 for i in range(CONST_TIMES):     winner = playGame()     if winner == 'f':         fst = fst + 1     elif winner == 's':         sec = sec + 1 secWinPro = round(float(sec) / CONST_TIMES, 3)  print secWinPro   The simulation probability is about 0.524. I want to know how to calculate the exact probability.
22292
Yesterday night, while I was trying to sleep, I found myself stuck with a simple statistics problem. Let's imagine we have a "magical coin", which is completely identical to a normal coin but for a thing: every time you toss the coin, the probability to get a head halves. So at t = 1 we have 50:50, then 25:75, then 12.5:87.5 and so on. At t = ∞ we are going to have 0:100.  My question is: if I toss this magical coin infinite times, can I say I am sure I am going to get at least one head? On one hand, I thought, the law of large numbers states that if an event is repeated infinite times, every state that is possible is bound to happen. On the other side, however, at t = ∞ the probability to get a head is zero.  Surely the solution of the problem is fairly easy, so what am I doing wrong?
63948
Suppose three players play the following game: Player 1 picks a number in $[0,1]$. Then player $2$ picks a number in the same range but different from the number player $1$ picked. Player $3$ also picks a number in the same range but different from the previous two. We then pick a random number in $[0,1]$ uniformly randomly. Whoever has a number closer to the random number we picked wins the game. Assume all players play optimally with the goal of maximizing their probability of winning. If one of them has several optimal choices, they pick one of them at random.  1)If Player 1 chooses zero, what is the best choice for player 2?  2)What is the best choice for player 1?  I have some trouble seeing how this problem is well-defined. For instance, if Player $1$ picks $0$ and Player $2$ picks 1, then I cannot see what the optimal choice would be for the last player since he has to pick different numbers. Can someone help?  EDIT: I now understand better how the problem works, but I still have no idea how to approach this. Can someone give me some hints?
90539
Apparently, the solution to the  is that a uniform probability distribution over the positive real numbers doesn't exist. Can anyone explain why this is the case and what probability distributions can exist over the positive real numbers (it seems that this would be quite limited, given that such a simple distribution is impossible)?
50050
The example in question is from Rick Durrett's "Elementrary Probability for Applications", and the setup is something like this:     Let $A$ be the event "Alice and Betty have the same birthday", $B$ be the event "Betty and Carol have the same birthday", and $C$ be the event "Carol and Alice have the same birthday".   Durrett goes on to demonstrate that each pair is independent, since for example,   $P(A \cap B) = P(A)P(B)$.   However, he concludes that $A, B$, and $C$ are not independent, since   $P(A \cap B \cap C) = \frac{1}{365^2} \neq \frac{1}{365^3} = P(A)P(B)P(C)$.  I understand the reasoning here, and that one can generally show that arbitrary events $X$ and $Y$ are not independent by showing that $P(X\cap Y) \neq P(X)P(Y)$.   I am a little new to probability, though, and don't understand why exactly $P(A \cap B \cap C) = \frac{1}{365^2}$.   My progress so far:   I do see why $P(A) = P(B) =P(C) = \frac{1}{365}$, and thus why $P(A)P(B)P(C) = \frac{1}{365^3}$.  It seems like the sample space $\Omega = \{ (a, b, c) \mid a,b,c \in [365] \}$ -- i.e., all of the possible triples of numbers from 1 to 365, where 1 denotes January 1st, 2 denotes January 2nd, etc. From that, I can conclude $|\Omega| = 365^3$, but I'm not sure where to go from here.   It seems like once a single birthday is chosen, the rest are completely determined if they're all equal to each other - is this a good direction to go in?
83383
This is not homework. I am interested in understanding if my logic is correct with this simple stats problem.  Let's say I have a 2 sided coin where the probability of flipping a head is $P(H)$ and the probability of flipping a tail is $1-P(H)$. Let's assume all flips have independent probabilities. Now, let's say I want to maximize my chances of predicting whether the coin will be a head or tail on the next flip. If $P(H) = 0.5$, I can guess heads or tails at random and the probability of me being correct is $0.5$.  Now, suppose that $P(H) = 0.2$, if I want to maximize my chances of guessing correctly, should I always guess tails where the probability is $0.8$?  Taking this one step further, if I had a 3-sided die, and the probability of rolling a 1, 2, or, 3 was $P(1)=0.1$, $P(2)=0.5$, and $P(3)=0.4$, should I always guess 2 to maximize my chances of guessing correctly? Is there another approach that would allow me to guess more accurately?
112474
So earlier today I came across , and I am having some trouble understanding the solution. The question is as follows:     You throw a fair six-sided die until you get 6. What is the expected   number of throws (including the throw giving 6) conditioned on the event   that all throws gave even numbers?   Quoted from Jimmy Jin in "Elchanan Mossel’s dice problem"  In the paper it goes on to state why a common wrong answer is $3$. Then afterwards explains that this problem has the same answer to,   "What is the expected number of times you can roll only $2$’s or $4$’s until you roll any other number?"  I don't understand why this is the case. If the original problem is asking for specifically a $6$, shouldn't that limit many of the possible sequences?  I also attempted to solve the problem using another method, but got an answer different from both $3$ and the correct answer of $1.5$.  I saw that possible sequences could have been something like:  $$\{6\}$$ $$\{2,6\}, \{4,6\}$$ $$\{2,2,6\}, \{2,4,6\}, \{4,2,6\}, \{4,4,6\}$$ $$\vdots$$  To which I set up the following summation and solved using :  $$\text{Expected Value} =\sum_{n=1}^\infty n\left( {\frac{1}{6}} \right)^n 2^{n-1} = 0.375$$ Obviously this is different and probably incorrect, but I can't figure out where the error in the thought process is.  Any help on understanding this would be greatly appreciated.  A blog post discussing the problem can be found
82257
I just came back from a class on Probability in Game Theory, and was musing over something in my head.  Assuming, for the sake of the question:   Playing cards in their current state have been around for approximately eight centuries A deck of playing cards is shuffled to a random configuration one billion times per day Every shuffle ever is completely (theoretically) random and unaffected by biases caused by human shuffling and the games the cards are used for By "deck of cards", I refer to a stack of unordered $52$ unique cards, with a composition that is identical from deck to deck.   This would, approximately, be on the order of $3 \cdot 10^{14}$ random shuffles in the history of playing cards.  If I were to shuffle a new deck today, completely randomly, what are the probabilistic odds (out of $1$) that you create a new unique permutation of the playing cards that has never before been achieved in the history of $3 \cdot 10^{14}$ similarly random shuffles?  My first thought was to think that it was a simple matter of $\frac{1}{52!} \cdot 3 \cdot 10^{14}$, but then I ran into things like .  While it is not analogous (I would have to be asking about the odds that any two shuffled decks in the history of shuffled decks ever matched), it has caused me to question my intuitive notions of Probability.  What is wrong in my initial approach, if it is wrong?  What is the true probability?  And, if the probability is less than $0.5$, if we how many more years (centuries?) must we wait, assuming the current rate of one billion shuffles per day, until we reach a state where the probability is $0.5$+?   $0.9$+?  (Out of curiosity, it would be neat to know the analogous birthday paradox answer, as well)
116172
Can someone please guide me to a way by which I can solve the following problem. There is a die and 2 players. Rolling stops as soon as some exceeds 100(not including 100 itself). Hence you have the following choices: 101, 102, 103, 104, 105, 106.  Which should I choose given first choice.  I'm thinking Markov chains, but is there a simpler way?   Thanks.  EDIT: I wrote dice instead of die. There is just one die being rolled
19374
Have been working on this problem for a while. No clue how to approach! Player A and Player B are playing a game with 3 possible results: win, tie and lose. Player A’s probabilities for each outcome are:  Win: 0.3  Tie: 0.2  Lose: 0.5   A win gives 2 points, tie gives each 1 point, and loss gives 0 points. The first of the two players to win 3 or more points than the other will win the match. What is the probability that Player A will eventually win? Thanks!
44641
Assume I have a distribution governing the possible outcome from a single random variable X.  This is something like [0.1, 0.4, 0.2, 0.3] for X being a value of either 1, 2, 3, 4.  Is it possible to sample from this distribution, i.e. generate pseudo random numbers upon each of the possible outcomes given the probability of that outcome. So if I wanted to know what the probability of getting a 2 is, the sampling operation may return 0.34 or something like that.  The reason I ask is that I'm trying to implement an action selection policy for a reinforcement learning method based on a research paper. From what I gather from the paper, the author is able to sample the distribution by "mapping the uniform distribution U[0,1] through cumulative probability density functions obtained by adaptive numerical integration". From this he then samples the transition probabilities for each trial...  I would be grateful for any info on this...  Thanks in advance
58384
I wish to draw integers from 1 to some specific $N$ by rolling some number of fair six-sided dice (d6). A good answer will explain why its method produces uniform and independent integers.  As an illustrative example, it would be helpful to explain how a solution works for the case of $N=150$.  Furthermore, I wish for the procedure to be as efficient as possible: roll the least number of d6 on average for each number generated.  Conversions from  to decimal are permissible.    .
30513
I was recently asked this question in an interview, but was completely stumped as to how to even begin answering it - it's been bugging me ever since, and I thought it was quite a nice question, so hopefully someone on here can help me out. Any help would be appreciated! Here goes:  You start off with £100 and you toss a coin 100 times. Before each toss you choose a stake $S$ which cannot be more than your current balance $x$ (so your maximum stake for the first toss is £100). If the coin comes up heads, you win $2S$ and your new balance is $x+2S$. If it comes up tails, you lose your stake and have $x-S$. How do you choose your stake so as to maximise your expected winnings from the game, not including the initial balance?  Cheers,  Boris
80386
I'm not a statistician. So, please bear with my blunders if any.  Would you please explain in a simple manner how simulation is done? I know that it picks some random sample from a normal distribution and use for simulating. But, don't understand clearly.
102462
You throw a fair $k$-sided dice repeatedly and keep track of all the results. You stop if you have seen every face exactly the same number of times. What is the expected number of times you have to throw the dice? Is that number even finite?  Start with the simplest example of a $2$-sided dice, ie a fair coin. There is a 50% chance that after 2 flips you will have one head and one tail so you stop. There is a 12.5% chance that after 2 flips you will be at 2:0 and continue but after 4 flips you will be at 2:2, so you stop. One can compute a few more terms but I don't see enough of a pattern to get a summable series.  It is not too hard to compute the probability that after $k\cdot m$ throws of a $k$-sided dice you get every face exactly $m$ times but these probabilities are not independent for different $m$ so I'm not sure whether that is helpful.  The relation to random walks looks useful. One can map the results of throwing a coin repeatedly to a random work on the integers. Seeing the same number of heads and tails is equivalent to coming back to the starting point (at zero). This is a well studied problem and it is known that you come back to zero with probability one in a finite time. The number I'm looking for would be the expected time when you get back to zero for the first time but I haven't found any results on that.  For $k$ bigger than $2$ (and even) the mapping to random walks is not bijective anymore. If you map the outcome of a $6$-sided dice throw to a random walk on the $3$-dimensional integer lattice with each face corresponding to a step in one of the 6 directions that a return to the origin is necessary but not sufficient for having seen each face the same number of times. However, it is known that for a random walk on the integer lattice in dimension of at least $3$, the chance to return to the origin in finite time is strictly smaller than $1$. So this should prove that for a dice with at least $6$ faces, the expected number of throws is not finite.  Is this a finite number for $k=2$ and $k$ between $3$ and $5$? Are there estimates for it?
72323
Ok, I know this is wrong, but I want someone to tell me why.   Let's take a normal heads tails example of a fair coin. The probability of getting head = 1/2. And I write this is because, either it will be heads, or not. Hence two cases that makes it 1/2.  Now, I know I can't do this to all the cases. For example, the probability of getting a 2 when I roll a dice. I know the answer is 1/6 but why can't I do, either the outcome will be 2 or not. And in that case, my probability is 1/2.
72158
I am playing Warlight online (something like Risk), and my goal is to create a bot which plays against other bots.  n=100 attacking troops will on average kill 60 (p=0.6) troops each turn,  n=100 defending troops will on average kill 70 (p=0.7) troops each turn. They attack exactly at the same time. Binomial distribution such that variance=n*p*(1-p)   My question is the following: imagine we have 40 troops and the enemy has 25 troops. I am interested in the case that I continuously attack. What would be the chance that I have won by turn X (e.g. X=5)?  For turn = 1, it is simply the cumulative sum from at least 25 kills:   $$\sum_{i=25}^{40} {40 \choose i} * 0.6^i * (1-0.6)^{(40-i)} = 0.440$$   I have played around with the binomial distribution, but I find it difficult to calculate because of this "in X turns"; it seems it really explodes the amount of calculations needed (by lack of a smart trick).  Can this be done analytically or am I best off just to simulate this (which I assume will be much slower)?  EDIT: Perhaps it can simply be done by using the 60% and 70%?