Homework 2 - Key

CHE 116: Numerical Methods and Statistics

Version 1.3 (1/19/2016)


1. Combiations and Permutations (8 Points)

  1. [1 point] How many ways can you rearrange the letters 'fodbar'?
  2. [1 point] How many ways can the 75 students in this class enter the classroom? How does that compare to the number of atoms in the universe $\left(10^{80}\right)$
  3. [1 point] A family may have up to 4 cars. On a street with 3 families, how many permutations of car ownership among the 3 familaies can their be?
  4. [1 point] You and your friends are playing a MOBA game and there are 100 characters you can use. You may only be one character. You play as a team of 5 characters with no repeated characters. How many character combinations can be on one team?
  5. [4 points] How many unqiue match-ups of 5 vs 5 teams can there be for this MOBA game? Hint: This will be a product of a few equations. Start by asking how many combinations of 10 there are and then think about splitting those up into 2 teams.

Answer 1.1

Permutation without replacement - $6! = 720$. Since the question asks about rearranging, the answer is 719


In [5]:
from scipy.special import comb, factorial

factorial(6)


Out[5]:
array(720.0)

Answer 1.2

Permutation without replacement - $75! = 2.5\times 10^{109}$. More possibilities than atoms in the universe


In [2]:
factorial(75)


Out[2]:
array(2.48091408113954e+109)

Answer 1.3

Permutation with replacement - $5^3 = 125$


In [1]:
5**3


Out[1]:
125

Answer 1.4

Combinations of fixed length without replacement - $\frac{n!}{l!(n - l)!} = \frac{100!}{5!(95)!} = 75,287,520$


In [4]:
comb(100, 5)


Out[4]:
75287520.0

Answer 1.5

Per the hint, our answer will the product of two quantities. The first is the number of 10-character combinations. That is the same as answer 1.4, but with $l=5$.

$$\frac{n!}{l!(n - l)!} = \frac{100!}{10!(100 - 10)!} = 17,310,309,456,440$$

In [5]:
comb(100, 10)


Out[5]:
17310309456440.0

Now we need to know how many ways each combination of 10 can be permutated into different teams. Let's consider 4 characters broken up into two teams to simplify. Let's represent the permutations as a sequence of numbers (e.g., 1234). Take the first two numbers as team A and the second two as team B. So the permutation 1234 is equivalent to 2134, 1243, and 2143. See the pattern? Every 4 permutations are equivalent to the teams becasue we can rearrange team A, team B or team A and team B. Mathematically, we have $n!$ permutations and can rearrange one of the teams by $\frac{n}{2}!$ without changing who's on the team. Since we can change both teams, that's $\frac{n}{2}! \times \frac{n}{2}!$. This gives a proposed equation:

$$\frac{n!}{\left(\frac{n}{2}\right)!\left(\frac{n}{2}\right)!}$$

Let's test it for 4. There are three teams we can make: 12 vs 34, 13 vs 24, 14 vs 23. The equation gives:

$$\frac{4!}{\left(\frac{4}{2}\right)!\left(\frac{4}{2}\right)!} = \frac{4\times 3 \times 2 \times 1}{(2 \times 1) (2 \times 1)} = \frac{4 \times 3}{2 \times 1} = 6$$

It overcounted by 2. Why? Because we didn't consider that we can switch the labels of team A and team B! Knowing that, we can arriave at the correct equation:

$$\frac{n!}{2\left(\frac{n}{2}\right)!\left(\frac{n}{2}\right)!}$$

Pluggin the numbers, we get

$$\frac{10!}{2\left(\frac{10}{2}\right)!\left(\frac{10}{2}\right)!}$$

In [6]:
factorial(10) / (2 * factorial(5) * factorial(5))


Out[6]:
126.0

In [7]:
comb(100, 10) * 126


Out[7]:
2181098991511440.0

The answer is 2,181,098,991,511,440 or 2.2 quadrillion


Alternative method

You could also view the process as choosing 5 team members and then choosing 5 from the remaining 95 characters. You must divide by two, however, becuase this method would count 1,2,3,4,5 vs 6,7,8,9,10 as different from 6,7,8,9,10 vs 1,2,3,4,5. Let's see what that gives:


In [8]:
comb(100, 5) * comb(95, 5) / 2


Out[8]:
2181098991511440.0

2. Two Dice (8 Points)

  1. What is the sample space size for 2 dice?
  2. [2 points] Is the sum of the 2 dice, $S(roll)$,an event, element of the sample space or random variable? What is $P(S = s)$?
  3. [2 points] What are the minimum and maximum values for $P(s)$ and $S$?
  4. [2 points] What is the expected value of $S$?
  5. You are playing the game craps, where on the first roll a sum of 2,3 and 12 results in an immediate loss. If you know that you lost after the first roll, what is the probability of the sum of dice? That is, what is $P(s\,|\, \textrm{loss})$? Show your work using the definition of a conditional distribution equation.

Answer 2.1

$$ Q = 6 \times 6 = 36$$

Answer 2.2

$S$ is a random variable. $P(S=s)$ is a probability.

Answer 2.3

$P(S = s): P(S=7) = \frac{6}{36} \,\textrm{and}\, P(S=2) = \frac{1}{36}$

$S$ :2 and 12

Answer 2.4

$$E[S] = \sum_x \frac{1}{Q} S(x) = \frac{1}{36} S(1,1) + \frac{1}{36} S(1,2) + \frac{1}{36} S(1,3) \ldots = \frac{252}{36} = 7 $$

Answer 2.5

$s$ was not specified, so our result should be a function!

$$P(S = s\,|\, loss) = \frac{P(loss, S = s)}{P(loss)}$$$$P(loss, S = s) = \left\{\begin{array}{lr}\\ P(S = s) & s = 2, 3, \textrm{or}\,12\\ 0 & \textrm{otherwise}\\ \end{array}\right.$$$$P(loss) = \sum_s P(loss, S = s) = P(S = 2) + P(S = 3) + P(S = 12) = \frac{4}{36}$$

Answer

$$P(S = 2\,|\,loss) = \frac{36}{4}\frac{1}{36} = \frac{1}{4}$$$$P(S = 3\,|\,loss) = \frac{36}{4}\frac{2}{36} = \frac{2}{4}$$$$P(S = 12\,|\,loss) = \frac{36}{4}\frac{1}{36} = \frac{1}{4}$$

3. Playing the Lottery (13 Poitns)

To play the megamillions, you chose 5 unique numbers from 1 to 75 and then one number from 1 to 15 that can overlapp with the previous 5. The first 5 numbers are note replaced, meaning during the drawing there are no repeated numbers. Each ticket costs \$2. Consider the following:

  1. [2 points] What is the sample space size for the lottery?
  2. [1 point] What is the probability of winning the lottery (matching all numbers)?
  3. [2 points] What is the expected value (in dollars) of the lottery as a function of jackpot amount? How big should the jackpot be for the expected value of playing exceed the cost of a ticket?
  4. [2 points] Assume that each ticket costs \$2 and 50% goes to the jackpot (the other is kept for profit). How many people must be playing for the expected value to exceed the price of a ticket?
  5. [4 ponits] Given the answer from part 4, what is the probability that no one else wins? Answer symbolically and numerically.
  6. [2 points] Let's simplify (we'll revisit later) and assume that if someone else wins, you collect half the jackpot. What's the expected value now?

3.1 Answer

This is a product sample space - the first five numbers and the second.

$$ \frac{75!}{5!(75 - 5)!} \times 15 = 258,890,850$$

In [2]:
from scipy.special import comb, factorial

comb(75, 5) * 15


Out[2]:
258890850.0

3.2 Answer

$$P(\textrm{win}) = \frac{1}{258,890,850}$$

3.3 Answer

It is left unspecified, but the random variable is the amount of money you win. Let this be $P(A=a)$, where $A$ means amount won. There are two values it can be: the jackpot and 0. The expected value equation is:

$$E[A] = \sum_a P(A = a)a = \frac{J}{258,890,850} + 0\times \left(1 - \frac{1}{258,890,850}\right)$$$$E[A] = \frac{J}{258,890,850}$$

3.4 Answer

$$E[A] > \$2$$$$\frac{J}{258,890,850} > \$2$$$$\frac{N \times \$2 \times 0.5}{258,890,850} > \$2$$$$N > 517,781,700$$

3.5 Answer

If no one wins, that's 517 million sequential loses. The probability of that is:

$$\prod_i^N \left(1 - \frac{1}{258,890,850}\right) = \left(1 - \frac{1}{258,890,850}\right)^N$$

You can use $N-1$ or $N$ here, depending on your definition of you and everyone playing. The answers are the same to 10 decimal places.

$$P(\textrm{no wins}) = 0.135$$

In [4]:
N = 258890850.0

print((1 - 1 / N)**(2 * N))

print((1 - 1 / N)**(2 * N - 1))


0.1353352844929083
0.13533528501565864

3.6 Answer

This is asking about the probability that there is at least one other winner. The probability of that is the complement of 3.5. We now have a different possible amount won values: you win alone, there is at least one other winner and you won, or you don't win. Notice these are $P(A = a)$ values. Let's compute these probabilities:

$$P(\textrm{you win})\times P(\textrm{no one wins}) = \left(\frac{1}{258,890,850}\right)\times 0.135$$$$P(\textrm{you win})\times [1 - P(\textrm{no one wins})] = \left(\frac{1}{258,890,850}\right)\times 0.865$$$$P(\textrm{you don't win}) \times P(\textrm{no one wins or someone wins}) = \left(1 - \frac{1}{258,890,850}\right) \times 1$$

The reason we have an or in the last statement because that is for $P(A = \$0)$, which can happen many ways. Now to compute expectation.

$$E[A] = \left(\frac{1}{258,890,850}\right)\times 0.135 \times J + \left(\frac{1}{258,890,850}\right)\times 0.865 \times \frac{J}{2} + 0$$

and we know $J = \$517,781,700$, because that comes out of our assumptions that led to the $N$ value. Thus:

$$E[A] = \$2 \times 0.135 + \$1 \times 0.865 = \$1.135$$

4. Countries & Career (8 Points)

You are a baby being carried in a stork to your parents. Your parents live in either:

  1. USA (u, 320)
  2. China (c, 1300)
  3. Germany (g, 80)

The probability of your birth location is proportional to the populations. As a baby, you are concerned with your career options, which are

  1. Rock star (r)
  2. Professor (p)
  3. Doctor (d)

Answer the following using $B$ as the random variable for birthplace and $J$ as the random variable for job. We have the following information:

$$P(J = r \,|\, B = c) = 0.05$$$$P(J = d \,|\, B = c) = 0.5$$$$P(J = r \,|\, B = u) = 0.8$$$$P(J = p\,|\, B = u) = 0.01$$$$P(J = p\,|\, B = g) = 0.75$$$$P(J = d \,|\, B = g) = 0.2$$
  1. [2 points] What is the probability that you will be a rockstar?
  2. [2 points] What is the probability that you will be a professor born in China?
  3. [1 point] You were born in Germany, what's the probability of becoming a rock star?
  4. [2 points] Consider the random variable $Z$, which indicates if you have a college degree (true for $J=d$ and $J=p$). What is $P(Z \,|\, B=g)$?
  5. [1 points] What is $P(B=u \,|\, Z)$?

4.1 Answer

We can use marginalization of the conditional to get this value:

$$P(J = r) = P(r\,|\,c)P(c) + P(r\,|\,u)P(u) + P(r\,|\,g)P(g)$$$$P(J = r) = 0.05\times \frac{1300}{320 + 80 + 1300} + 0.8\times\frac{320}{320 + 80 + 1300} + (1 - 0.2 - 0.75)\times\frac{80}{320 + 80 + 1300}$$$$P(J = r) = 0.19)$$

In [2]:
pop = 320 + 80 + 1300
0.05 * (1300 / pop) + 0.8 * 320 / (pop) + (1 - 0.2 - 0.75) * 80 / pop


Out[2]:
0.15294117647058822

4.2 Answer

We are being asked $P(J=p, B=c)$. We can use the equation for definition of a conditional.

$$P(J = p, B = c) = p(J= p\,|\, B = c)\,P(B = c) = (1 - 0.05 - 0.5)\frac{1300}{320 + 80 + 1300}$$$$P(J = p, B = c) = 0.34$$

In [7]:
(1 - 0.05 - 0.5) * 1300 / pop


Out[7]:
0.3441176470588235

4.3 Answer

We are being asked $P(J = r \,|\, B = g)$, which is just $(1 - 0.75 - 0.2) = 0.05$

4.4 Answer

$$P(Z \,|\, B =g) = P(J = d \,|\, B=g) + P(J = d \,|\, B = g) = 0.75 + 0.2 = 0.95$$

4.5 Answer

We can use Bayes' theorem to switch the conditional to be like the previous problem. We'll use "not a rockstar" to compute Z for many of the conditionals.

$$P(B = u \,|\, Z) = \frac{P(Z \,|\, B = u)P(u)}{P(Z)}$$$$P(Z) = P(Z \,|\, B = u) P(u) + P(Z \,|\, B = g) P(g) + P(Z \,|\, B = c)P(c)$$$$P(Z) = (1 - 0.8)\frac{320}{1300 + 80 + 320} + 0.95 \frac{80}{1300 + 320 + 80} + 0.95\frac{1300}{320 + 80 + 1300} = 0.81$$

In [4]:
pz = 0.2 * 320 / pop + 0.95 * 80 / pop + 0.95 * 1300 / pop
ans = ((1 - 0.8) * 320 / pop) / pz
print(ans)


0.0465454545455
$$P(B = u \,|\, Z) = 0.047$$