# Khan/khan-exercises

516 lines (482 sloc) 30 KB
 Independent probability
random() < 0.5 ? i18n._("heads") : i18n._("tails") randFromArray([ /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("a 1"), [1]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("a 2"), [2]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("a 3"), [3]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("a 4"), [4]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("a 5"), [5]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("a 6"), [6]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("at least a 2"), [2, 3, 4, 5, 6]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("at least a 3"), [3, 4, 5, 6]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("at least a 4"), [4, 5, 6]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("more than a 2"), [3, 4, 5, 6]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("more than a 3"), [4, 5, 6]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("more than a 4"), [5, 6]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("less than a 4"), [1, 2, 3]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("less than a 5"), [1, 2, 3, 4]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("less than a 6"), [1, 2, 3, 4, 5]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("an even number"), [2, 4, 6]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("an even number"), [2, 4, 6]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("an odd number"), [1, 3, 5]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("an odd number"), [1, 3, 5]], /* I18N: Shows up in a question of the form, "what is the probability you will ... roll ___ ?" */ [i18n._("a prime number"), [2, 3, 5]] ]) RESULT_POSSIBLE.length / getGCD(RESULT_POSSIBLE.length,12) 12 / getGCD(RESULT_POSSIBLE.length,12)

If you flip a coin and roll a 6-sided die, what is the probability that you will flip a HT and roll RESULT_DESC?

0.5 * RESULT_POSSIBLE.length / 6

Flipping a HT and rolling RESULT_DESC are independent events: they don't affect each other. So, to get the probability of both happening, we just need to multiply the probability of one by the probability of the other.

The probability of flipping a HT is \dfrac{1}{2}.

The probability of rolling RESULT_DESC is \dfrac{RESULT_POSSIBLE.length}{6}, since there is RESULT_POSSIBLE.length outcome which satisfy our condition (namely, toSentence(RESULT_POSSIBLE)), and 6 total possible outcomes. The probability of rolling RESULT_DESC is \dfrac{RESULT_POSSIBLE.length}{6}, since there are RESULT_POSSIBLE.length outcomes which satisfy our condition (namely, toSentence(RESULT_POSSIBLE)), and 6 total possible outcomes.

The probability of rolling RESULT_DESC is \dfrac{RESULT_POSSIBLE.length}{6}, since there is RESULT_POSSIBLE.length outcome which satisfies our condition (namely, toSentence(RESULT_POSSIBLE)), and 6 total possible outcomes. The probability of rolling RESULT_DESC is \dfrac{RESULT_POSSIBLE.length}{6}, since there are RESULT_POSSIBLE.length outcomes which satisfies our condition (namely, toSentence(RESULT_POSSIBLE)), and 6 total possible outcomes.

So, the probability of both these events happening is \dfrac{1}{2} \cdot \dfrac{RESULT_POSSIBLE.length}{6} = \dfrac{PRETTY_N}{PRETTY_D}.

[["Carmelo Anthony", .84], ["Trevor Ariza", .70], ["Michael Beasley", .75], ["Carlos Boozer", .70], ["Elton Brand", .78], ["Kobe Bryant", .83], ["DeMarcus Cousins", .69], ["Glen Davis", .74], ["Luol Deng", .75], ["Tim Duncan", .72], ["Kevin Durant", .88], ["Raymond Felton", .81], ["Kevin Garnett", .86], ["Pau Gasol", .82], ["Manu Ginobili", .87], ["Grant Hill", .83], ["LeBron James", .76], ["Antawn Jamison", .73], ["Shawn Marion", .77], ["Joakim Noah", .74], ["Chris Paul", .88], ["Paul Pierce", .86], ["Derrick Rose", .86], ["Amar'e Stoudemire", .79], ["John Wall", .77]] random() < 0.5 randFromArray(FREE_THROWS) ALL ? PR : roundTo(2, 1-PR) PROB * 10 pow(PROB, 3) randRange(4,9) localeToFixed(PROB * 100, 0) localeToFixed(pow(PROB,2) * 100, 0) (pow(PROB,3) * 100) < 0.5 ? localeToFixed(pow(PROB,3) * 100, 1) : localeToFixed(pow(PROB,3) * 100, 0) shuffle( [localeToFixed(PR, 2) + "^" + STREAK, STREAK + " \\cdot" + localeToFixed(PR, 2), STREAK + " \\cdot" + "(1 - " + localeToFixed(PR, 2) + ")", "(1 - " + localeToFixed(PR, 2) + ")^" + STREAK]) ALL ? localeToFixed(PR, 2) + "^" + STREAK : "(1 - " + localeToFixed(PR, 2) + ")^" + STREAK

PLAYER is shooting free throws. Making or missing free throws doesn't change the probability that he will make his next one, and he makes his free throws localeToFixed(PR*100, 0)\% of the time.

What is the probability of PLAYER making all of his next STREAK free throw attempts? What is the probability of PLAYER making none of his next STREAK free throw attempts?

\large{ANS}
• \large{OPTIONS[0]}
• \large{OPTIONS[1]}
• \large{OPTIONS[2]}
• \large{OPTIONS[3]}

We know that \blue{SINGLE_PCT \%} of the time, he'll make his first shot.

init({ range: [[-1, 11], [-1, 1]] }); line([0, 0], [10, 0]); line([10,-0.2], [10,0.2]); label([PROB10,-0.53], SINGLE_PCT + "\\%", "center"); style({ stroke: "BLUE", strokeWidth: 3 }); line([0,-0.2], [0,0.2]); line([0,0], [PROB10,0]); line([PROB10,-0.2], [PROB10,0.2]);

Then SINGLE_PCT \% of the time he makes his first shot, he will also make his second shot, and localeToFixed((1-PROB)*100, 0) \% of the time he makes his first shot, he will miss his second shot.

init({ range: [[-1, 11], [-1, 1]] }); line([0, 0], [10, 0]); line([10,-0.2], [10,0.2]); label([PROB10, -0.53], SINGLE_PCT + "\\%", "center"); style({ stroke: "#888", strokeWidth: 3 }); line([PROB * PROB10,0], [PROB10,0]); line([PROB10,-0.2], [PROB10,0.2]); style({ stroke: "PURPLE", strokeWidth: 3 }); line([0,-0.2], [0,0.2]); line([0,0], [PROB * PROB10,0]); line([PROB * PROB10,-0.2], [PROB * PROB10,0.2]);

Notice how we can completely ignore the rightmost section of the line now, because those were the times that he missed the first free throw, and we only care about if he makes the first and the second. So the chance of making two free throws in a row is SINGLE_PCT\% of the times that he made the first shot, which happens SINGLE_PCT\% of the time in general.

This is SINGLE_PCT\% \cdot SINGLE_PCT\%, or localeToFixed(PROB, 2) \cdot localeToFixed(PROB, 2) \approx localeToFixed(PROB*PROB, 3).

We can repeat this process again to get the probability of making three free throws in a row. We simply take SINGLE_PCT\% of probability that he makes two in a row, which we know from the previous step is localeToFixed(PROB*PROB, 3) \approx \purple{TWO_PCT\%}.

init({ range: [[-1, 11], [-1, 1]] }); line([0, 0], [10, 0]); line([10,-0.2], [10,0.2]); label([PROB10, -0.53], SINGLE_PCT + "\\%", "center"); line([PROB10,-0.2], [PROB10,0.2]); label([PROB * PROB10, -0.53], TWO_PCT + "\\%", "center"); style({ stroke: "PURPLE", strokeWidth: 3 }); line([0,-0.2], [0,0.2]); line([0,0], [PROB * PROB10,0]); line([PROB * PROB10,-0.2], [PROB * PROB10,0.2]);

SINGLE_PCT\% of \purple{TWO_PCT\%} is localeToFixed(PROB, 2) \cdot localeToFixed(PROB * PROB, 3) \approx localeToFixed(PROB_CUBED, 3), or about \green{THREE_PCT\%}:

init({ range: [[-1, 11], [-1, 1]] }); line([0, 0], [10, 0]); line([10,-0.2], [10,0.2]); label([PROB10, -0.53], SINGLE_PCT + "\\%", "center"); line([PROB10,-0.2], [PROB10,0.2]); label([PROB*PROB10, -0.53], TWO_PCT + "\\%", "center"); label([PROB_CUBED*10, -0.53], THREE_PCT + "\\%", "center"); style({ stroke: "#888", strokeWidth: 3 }); line([PROB_CUBED * 10,0], [PROB * PROB10,0]); line([PROB * PROB10,-0.2], [PROB * PROB10,0.2]); style({ stroke: "GREEN", strokeWidth: 3 }); line([0,-0.2], [0,0.2]); line([0,0], [PROB_CUBED*10,0]); line([PROB_CUBED*10,-0.2], [PROB_CUBED*10,0.2]);

There is a pattern here: the chance of making two free throws in a row was localeToFixed(PROB, 2) \cdot localeToFixed(PROB, 2), and the probability of making three in a row was localeToFixed(PROB, 2) \cdot localeToFixed(PROB * PROB, 3) = localeToFixed(PROB, 2) \cdot (localeToFixed(PROB, 2) \cdot localeToFixed(PROB, 2)) = localeToFixed(PROB, 2)^3.

In general, you can continue in this way to find the probability of making any number of shots.

The probability of making STREAK free throws in a row is localeToFixed(PROB, 2) ^ STREAK.

We know that \blue{SINGLE_PCT \%} of the time, he'll miss his first shot (100 \% - localeToFixed(PR*100, 0) \% = SINGLE_PCT \%).

init({ range: [[-1, 11], [-1, 1]] }); line([0, 0], [10, 0]); line([10,-0.2], [10,0.2]); label([PROB10,-0.53], SINGLE_PCT + "\\%", "center"); style({ stroke: "BLUE", strokeWidth: 3 }); line([0,-0.2], [0,0.2]); line([0,0], [PROB10,0]); line([PROB10,-0.2], [PROB10,0.2]);

Then SINGLE_PCT \% of the time he misses his first shot, he will also miss his second shot, and localeToFixed((1-PROB)*100, 0) \% of the time he misses his first shot, he will make his second shot.

init({ range: [[-1, 11], [-1, 1]] }); line([0, 0], [10, 0]); line([10,-0.2], [10,0.2]); label([PROB10, -0.53], SINGLE_PCT + "\\%", "center"); style({ stroke: "#888", strokeWidth: 3 }); line([PROB * PROB10,0], [PROB10,0]); line([PROB10,-0.2], [PROB10,0.2]); style({ stroke: "PURPLE", strokeWidth: 3 }); line([0,-0.2], [0,0.2]); line([0,0], [PROB * PROB10,0]); line([PROB * PROB10,-0.2], [PROB * PROB10,0.2]);

Notice how we can completely ignore the rightmost section of the line now, because those were the times that he made the first free throw, and we only care about if he misses the first and the second. So the chance of missing two free throws in a row is SINGLE_PCT\% of the times that he missed the first shot, which happens SINGLE_PCT\% of the time in general.

This is SINGLE_PCT\% \cdot SINGLE_PCT\%, or localeToFixed(PROB, 2) \cdot localeToFixed(PROB, 2) \approx localeToFixed(PROB * PROB, 3).

We can repeat this process again to get the probability of missing three free throws in a row. We simply take SINGLE_PCT\% of probability that he misses two in a row, which we know from the previous step is localeToFixed(PROB*PROB, 3) \approx \purple{TWO_PCT\%}.

init({ range: [[-1, 11], [-1, 1]] }); line([0, 0], [10, 0]); line([10,-0.2], [10,0.2]); label([PROB10, -0.53], SINGLE_PCT + "\\%", "center"); line([PROB10,-0.2], [PROB10,0.2]); label([PROB * PROB10, -0.53], TWO_PCT + "\\%", "center"); style({ stroke: "PURPLE", strokeWidth: 3 }); line([0,-0.2], [0,0.2]); line([0,0], [PROB * PROB10,0]); line([PROB * PROB10,-0.2], [PROB*PROB10,0.2]);

SINGLE_PCT\% of \purple{TWO_PCT\%} is localeToFixed(PROB, 2) \cdot localeToFixed(PROB*PROB, 3) \approx localeToFixed(PROB_CUBED, 3), or about \green{THREE_PCT\%}:

init({ range: [[-1, 11], [-1, 1]] }); line([0, 0], [10, 0]); line([10,-0.2], [10,0.2]); label([PROB10, -0.53], SINGLE_PCT + "\\%", "center"); line([PROB10,-0.2], [PROB10,0.2]); label([PROB * PROB10, -0.53], TWO_PCT + "\\%", "center"); style({ stroke: "#888", strokeWidth: 3 }); line([PROB_CUBED * 10,0], [PROB * PROB10,0]); line([PROB * PROB10,-0.2], [PROB * PROB10,0.2]); style({ stroke: "GREEN", strokeWidth: 3 }); line([0,-0.2], [0,0.2]); line([0,0], [PROB_CUBED * 10,0]); line([PROB_CUBED * 10,-0.2], [PROB_CUBED * 10,0.2]);

There is a pattern here: the chance of missing two free throws in a row was localeToFixed(PROB, 2) \cdot localeToFixed(PROB, 2), and the probability of missing three in a row was localeToFixed(PROB, 2) \cdot localeToFixed(PROB*PROB, 3) = localeToFixed(PROB, 2) \cdot (localeToFixed(PROB, 2) \cdot localeToFixed(PROB, 2)) = localeToFixed(PROB, 2)^3.

In general, you can continue in this way to find the probability of missing any number of shots.

The probability of missing STREAK free throws in a row is localeToFixed(PROB, 2) ^ STREAK = ANS.

randRange(1,4) CAPTAIN_NUM + randRange(1,6) CAPTAIN_NUM/CAPTAIN_DEM randRange(1,4) PIRATE_NUM + randRange(4,6) PIRATE_NUM/PIRATE_DEM [getGCD(CAPTAIN_NUM,CAPTAIN_DEM), getGCD(PIRATE_NUM,PIRATE_DEM)] "\\dfrac{" + CAPTAIN_NUM/CGCD + "}{" + CAPTAIN_DEM/CGCD + "}" "\\dfrac{" + (CAPTAIN_DEM/CGCD - CAPTAIN_NUM/CGCD) + "}{" + CAPTAIN_DEM/CGCD + "}" "\\dfrac{" + PIRATE_NUM/PGCD + "}{" + PIRATE_DEM/PGCD + "}" "\\dfrac{" + (PIRATE_DEM/PGCD - PIRATE_NUM/PGCD) + "}{" + PIRATE_DEM/PGCD + "}" randRange(0,3) [i18n._("the Captain hits the pirate ship, but the pirate misses"), i18n._("the pirate hits the Captain's ship, but the Captain misses"), i18n._("both the pirate and the Captain hit each other's ships"), i18n._("both the Captain and the pirate miss")][INDEX] [[CAPTAIN_NUM * (PIRATE_DEM-PIRATE_NUM), CAPTAIN_DEM*PIRATE_DEM, CAPTAIN_PROB*(1-PIRATE_PROB)], [(CAPTAIN_DEM-CAPTAIN_NUM) * PIRATE_NUM, CAPTAIN_DEM*PIRATE_DEM, (1-CAPTAIN_PROB)*PIRATE_PROB], [CAPTAIN_NUM * PIRATE_NUM, CAPTAIN_DEM*PIRATE_DEM, CAPTAIN_PROB*PIRATE_PROB], [(CAPTAIN_DEM-CAPTAIN_NUM) * (PIRATE_DEM-PIRATE_NUM), CAPTAIN_DEM*PIRATE_DEM, (1-CAPTAIN_PROB)*(1-PIRATE_PROB)]][INDEX] INDEX === 0 || INDEX === 2 INDEX === 1 || INDEX === 2

Captain person(1) has a ship, the H.M.S. Khan. The ship is two furlongs from the dread pirate person(2) and his merciless band of thieves.The ship is two furlongs from the dread pirate person(2) and her merciless band of thieves.

The Captain has probability C_HIT_PRETTY of hitting the pirate ship. The pirate only has one good eye, so he hits the Captain's ship with probability P_HIT_PRETTY.The Captain has probability C_HIT_PRETTY of hitting the pirate ship. The pirate only has one good eye, so she hits the Captain's ship with probability P_HIT_PRETTY.

If both fire their cannons at the same time, what is the probability that QUESTION?

If the Captain hits the pirate ship, it won't affect whether he's also hit by the pirate's cannons (and vice-versa), because they both fired at the same time. So, these events are independent.

If the Captain hits the pirate ship, it won't affect whether she's also hit by the pirate's cannons (and vice-versa), because they both fired at the same time. So, these events are independent.

Since they are independent, in order to get the probability that QUESTION, we just need to multiply together the probability that the captain hits and the probability that the pirate hits. Since they are independent, in order to get the probability that QUESTION, we just need to multiply together the probability that the captain hits and the probability that the pirate misses. Since they are independent, in order to get the probability that QUESTION, we just need to multiply together the probability that the captain misses and the probability that the pirate hits. Since they are independent, in order to get the probability that QUESTION, we just need to multiply together the probability that the captain misses and the probability that the pirate misses.

The probability that the Captain hits is C_HIT_PRETTY.

The probability that the Captain misses is 1 - (the probability the Captain hits), which is 1 - C_HIT_PRETTY = C_MISS_PRETTY.

The probability that the pirate hits is P_HIT_PRETTY.

The probability that the pirate misses is 1 - (the probability the pirate hits), which is 1 - P_HIT_PRETTY = P_MISS_PRETTY.

So, the probability that QUESTION is C ? C_HIT_PRETTY : C_MISS_PRETTY \cdot P ? P_HIT_PRETTY : P_MISS_PRETTY = \dfrac{ANS_N/getGCD(ANS_N,ANS_D)}{ANS_D/getGCD(ANS_N,ANS_D)}.