Skip to content
453 lines (443 sloc) 24.1 KB
<!DOCTYPE html>
<html data-require="math word-problems math-format">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Dependent probability</title>
<script data-main="../local-only/main.js" src="../local-only/require.js"></script>
</head>
<body>
<div class="exercise">
<div class="problems">
<div id="students">
<div class="vars">
<var id="TOTAL">randRange(6, 10)</var>
<var id="SPECIAL">randRange(2, TOTAL-2)</var>
<var id="ALL">random() &lt; 0.5</var>
<var id="CHOSEN">randRange(2,
Math.min(ALL ? SPECIAL : TOTAL-SPECIAL,4))
</var>
<var id="EVENT_PY, EVENT_PN, EVENT_Y, EVENT_N">
randFromArray(
[["will visit Mars",
"will not visit Mars",
"will visit Mars",
"will not visit Mars"],
["have done their homework",
"have not done their homework",
"has done his homework",
"has not done his homework"],
["are secretly robots",
"are not secretly robots",
"is secretly a robot",
"is not secretly a robot"],
["forgot their lunch",
"remembered their lunch",
"forgot his lunch",
"remembered his lunch"],
["are martial arts masters",
"are not martial arts masters",
"is a martial arts master",
"is not a martial arts master"],
["play soccer",
"do not play soccer",
"plays soccer",
"does not play soccer"]])
</var>
<var id="EVENT_P">ALL ? EVENT_PY : EVENT_PN</var>
<var id="EVENT_S">ALL ? EVENT_Y : EVENT_N</var>
<var id="PROBS">
(function(){
prs = [];
_.each(_.range(CHOSEN), function(i) {
if(ALL) {
num = (SPECIAL - i);
den = (TOTAL - i);
prs.push([num,den]);
} else {
num = (TOTAL - SPECIAL - i);
den = (TOTAL - i);
prs.push([num,den]);
}
});
return prs;
})()
</var>
<var id="ANS_N">_.reduce(PROBS, function(n, frac) { return n * frac[0]; }, 1)</var>
<var id="ANS_D">_.reduce(PROBS, function(n, frac) { return n * frac[1]; }, 1)</var>
<var id="GCD">getGCD(ANS_N, ANS_D)</var>
</div>
<p class="problem">
In a class of <code><var>TOTAL</var></code>,
there are <code><var>SPECIAL</var></code> students who
<var>EVENT_PY</var>.
</p>
<p class="question">
If the teacher chooses <code><var>CHOSEN</var></code>
students, what is the probability that
<var>ALL ? ((CHOSEN === 2) ? "both" : "all " + cardinalThrough20(CHOSEN)) :
((CHOSEN === 2) ? "neither" : "none of the " + cardinalThrough20(CHOSEN))</var>
of them <var>EVENT_PY</var>?
</p>
<div class="solution" data-forms="proper, improper, decimal, percent" data-simplify="optional">
<var>ANS_N / ANS_D</var>
</div>
<div class="hints">
<p data-if="CHOSEN > 2">
We can think about this problem as the probability of
<code><var>CHOSEN</var></code> events happening.
<br><br>
The first event is the teacher choosing one student
who <var>EVENT_S</var>. The second event is the teacher
choosing another student who <var>EVENT_S</var>, given
that the teacher already chose someone who
<var>EVENT_S</var>
, and so on.
</p><p data-else="">
We can think about this problem as the probability of
<code><var>CHOSEN</var></code> events happening.
<br><br>
The first event is the teacher choosing one student
who <var>EVENT_S</var>. The second event is the teacher
choosing another student who <var>EVENT_S</var>, given
that the teacher already chose someone who
<var>EVENT_S</var>
.
</p>
<p>
The probabilty that the teacher will choose someone
who <var>EVENT_S</var> is the number of students who
<var>EVENT_P</var> divided by the total number of
students: <code>\dfrac{<var>PROBS[0][0]</var>}
{<var>PROBS[0][1]</var>}</code>.
</p>
<p>
Once the teacher's chosen one student, there are only
<code><var>TOTAL-1</var></code> left.
</p>
<p>
There's also one fewer student who <var>EVENT_S</var>,
since the teacher isn't going to pick the same student
twice.
</p>
<p>
So, the probability that the teacher picks a second
student who also <var>EVENT_S</var> is
<code>\dfrac{<var>PROBS[1][0]</var>}
{<var>PROBS[1][1]</var>}</code>.
</p>
<p data-if="CHOSEN > 2">
The probability of the teacher picking two
students who <var>EVENT_P</var> must then be
<code>\dfrac{<var>PROBS[0][0]</var>}
{<var>PROBS[0][1]</var>} \cdot
\dfrac{<var>PROBS[1][0]</var>}
{<var>PROBS[1][1]</var>}</code>.
</p>
<p data-if="CHOSEN > 2">
We can continue using the same logic for the rest of
the students the teacher picks.
</p>
<div>
<p>
So, the probability of the teacher picking
<code><var>CHOSEN</var></code> students such that
<var>ALL ? ((CHOSEN === 2) ? "both" : "all")
: "none"</var> of them
<var>EVENT_PY</var> is:
</p>
<p><code>\qquad<var>_.map(PROBS, function(p){
return "\\dfrac{"+p[0]+"}{"+p[1]+"}";
}).join("\\cdot")</var> =
\dfrac{<var>ANS_N</var>}{<var>ANS_D</var>}
<span data-if="GCD !== 1">
= <var>fractionReduce(ANS_N, ANS_D)</var>
</span></code>
</p>
</div>
</div>
</div>
<div id="marbles">
<div class="vars">
<var id="CONTAINER">
randFromArray(["bag", "jar", "box", "goblet"])
</var>
<var id="MARBLE">
randFromArray(["marble", "ball", "jelly bean"])
</var>
<var id="REDMAR">randRange(2, 6)</var>
<var id="GREENMAR">randRange(2, 6)</var>
<var id="BLUEMAR">randRange(2, 6)</var>
<var id="TOTAL">REDMAR + GREENMAR + BLUEMAR</var>
<var id="COLOR_ONE,NUM_ONE">
randFromArray([["red", REDMAR], ["green", GREENMAR],
["blue", BLUEMAR]])
</var>
<var id="COLOR_T,NUM_TWO">
randFromArray([["red", REDMAR], ["green", GREENMAR],
["blue", BLUEMAR]])
</var>
<var id="COLOR_TWO">
COLOR_ONE === COLOR_T ?
"another " + COLOR_T : "a " + COLOR_T
</var>
<var id="AFTER_NUM">
COLOR_ONE === COLOR_T ?
NUM_TWO - 1 : NUM_TWO
</var>
<var id="ANS_N">NUM_ONE * AFTER_NUM</var>
<var id="ANS_D">TOTAL * (TOTAL - 1)</var>
</div>
<p class="problem">
</p><p>A <var>CONTAINER</var> contains
<code><var>REDMAR</var></code> red <var>MARBLE</var>s,
<code><var>GREENMAR</var></code> green <var>MARBLE</var>s,
and <code><var>BLUEMAR</var></code>
blue <var>MARBLE</var>s.</p>
<p></p>
<p class="question">
If we choose a <var>MARBLE</var>, then another <var>MARBLE</var>
<em>without putting the first one back in the <var>
CONTAINER</var></em>, what is the probability that
the first <var>MARBLE</var> will be <var>COLOR_ONE</var>
and the second will be <var>COLOR_T</var><var>COLOR_ONE === COLOR_T ? " as well?" : "?"</var>
</p>
<div class="solution" data-forms="proper, improper, decimal, percent" data-simplify="optional">
<var>ANS_N / ANS_D</var>
</div>
<div class="hints">
<p>
The probability of event A happening, then event B, is
the probability of event A happening times
the probability of event B happening <em>given that
event A already happened</em>.
<br><br>
In this case, event A is picking a <var>COLOR_ONE</var>
<var>MARBLE</var> and leaving it out.
Event B is picking <var>COLOR_TWO</var>
<var>MARBLE</var>.
</p>
<p>
Let's take the events one at at time.
What is the probability that the first <var>MARBLE</var> chosen
will be <var>COLOR_ONE</var>?
</p>
<p>
There are <code><var>NUM_ONE</var></code>
<var>COLOR_ONE</var> <var>MARBLE</var>s,
and <code><var>TOTAL</var></code> total, so the
probability we will pick a <var>COLOR_ONE</var>
<var>MARBLE</var> is
<code>\dfrac{<var>NUM_ONE</var>}
{<var>TOTAL</var>}</code>.
</p>
<p>
After we take out the first <var>MARBLE</var>, we
don't put it back in, so there are only
<code><var>TOTAL-1</var></code> <var>MARBLE</var>s
left.
</p>
<p data-if="COLOR_ONE === COLOR_T">
Also, we've taken out one of the <var>COLOR_ONE</var>
<var>MARBLE</var>s, so there are only
<code><var>AFTER_NUM</var></code> left altogether.
</p>
<p data-else="">
Since the first <var>MARBLE</var> was
<var>COLOR_ONE</var>, there are still
<code><var>AFTER_NUM</var></code>
<var>COLOR_T</var> <var>MARBLE</var>s
left.
</p>
<p>
So, the probability of picking <var>COLOR_TWO</var>
<var>MARBLE</var> after taking out a
<var>COLOR_ONE</var> <var>MARBLE</var> is
<code>\dfrac{<var>AFTER_NUM</var>}
{<var>TOTAL-1</var>}</code>.
</p>
<p>
Therefore, the probability of picking a
<var>COLOR_ONE</var> <var>MARBLE</var>, then
<var>COLOR_TWO</var> <var>MARBLE</var>
is <code>\dfrac{<var>NUM_ONE</var>}{<var>TOTAL</var>}
\cdot \dfrac{<var>AFTER_NUM</var>}{<var>TOTAL-1</var>}
= \dfrac{<var>ANS_N</var>}{<var>ANS_D</var>}
= <var>fractionReduce(ANS_N, ANS_D)</var></code>
</p>
</div>
</div>
<div id="YARR">
<div class="vars" data-ensure="CAPTAIN_PROB &gt; PIRATE_PROB">
<var id="C_FIRST">random() &lt; 0.5</var>
<var id="CAPTAIN_NUM">randRange(1,4)</var>
<var id="CAPTAIN_DEM">CAPTAIN_NUM + randRange(1,6)</var>
<var id="CAPTAIN_PROB">CAPTAIN_NUM/CAPTAIN_DEM</var>
<var id="PIRATE_NUM">randRange(1,4)</var>
<var id="PIRATE_DEM">PIRATE_NUM + randRange(4,6)</var>
<var id="PIRATE_PROB">PIRATE_NUM/PIRATE_DEM</var>
<var id="CGCD, PGCD">[getGCD(CAPTAIN_NUM,CAPTAIN_DEM), getGCD(PIRATE_NUM,PIRATE_DEM)]</var>
<var id="C_HIT_PRETTY">"\\dfrac{" + CAPTAIN_NUM/CGCD + "}{" + CAPTAIN_DEM/CGCD + "}"</var>
<var id="C_MISS_PRETTY">"\\dfrac{" + (CAPTAIN_DEM/CGCD - CAPTAIN_NUM/CGCD) + "}{" + CAPTAIN_DEM/CGCD + "}"</var>
<var id="P_HIT_PRETTY">"\\dfrac{" + PIRATE_NUM/PGCD + "}{" + PIRATE_DEM/PGCD + "}"</var>
<var id="P_MISS_PRETTY">"\\dfrac{" + (PIRATE_DEM/PGCD - PIRATE_NUM/PGCD) + "}{" + PIRATE_DEM/PGCD + "}"</var>
<var id="INDEX">randRange(0,2)</var>
<var id="QUESTION">
(function(){
if(C_FIRST) {
return ["the Captain hits the pirate ship, but the pirate misses",
"the Captain misses the pirate ship, but the pirate hits",
"both the Captain and the pirate hit each other's ships"][INDEX];
} else {
return ["the pirate misses the Captain's ship, but the Captain hits",
"the pirate hits the Captain's ship, but the Captain misses",
"both the pirate and the Captain hit each other's ships"][INDEX];
}
})()
</var>
<var id="ANS_N, ANS_D">
(function(){
if(C_FIRST) {
return [[CAPTAIN_NUM, CAPTAIN_DEM],
[(CAPTAIN_DEM - CAPTAIN_NUM) * PIRATE_NUM, CAPTAIN_DEM * PIRATE_DEM],
[0, 1]][INDEX];
} else {
return [[CAPTAIN_NUM * (PIRATE_DEM - PIRATE_NUM), CAPTAIN_DEM * PIRATE_DEM],
[PIRATE_NUM, PIRATE_DEM],
[0, 1]][INDEX];
}
})()
</var>
<var id="ANSWER">ANS_N / ANS_D</var>
<var id="C">INDEX === 0 || INDEX === 2</var>
<var id="P">INDEX === 1 || INDEX === 2</var>
<var id="EV_A, PR_A">
[C_FIRST ? (C ? "the Captain hitting the pirate ship" : "the Captain missing the pirate ship")
: (P ? "the pirate hitting the Captain's ship" : "the pirate missing the Captain's ship"),
C_FIRST ? (C ? C_HIT_PRETTY : C_MISS_PRETTY) : (P ? P_HIT_PRETTY : P_MISS_PRETTY)]
</var>
<var id="EV_B, PR_B">
(function(){
if(C_FIRST) {
if(P &amp;&amp; C) {
return ["the pirate hitting the Captain's ship", 0];
} else if(P) {
return ["the pirate hitting the Captain's ship", P_HIT_PRETTY];
} else if(!P &amp;&amp; C) {
return ["the pirate missing the Captain's ship", 1];
} else {
return ["the pirate missing the Captain's ship", P_MISS_PRETTY];
}
} else {
if(C &amp;&amp; P) {
return ["the Captain hitting the pirate ship", 0];
} else if(C) {
return ["the Captain hitting the pirate ship", C_HIT_PRETTY];
} else if(!C &amp;&amp; P) {
return ["the Captain missing the pirate ship", 1];
} else {
return ["the Captain missing the pirate ship", C_MISS_PRETTY];
}
}
})()
</var>
<var id="DISTANCE">cardinalThrough20(randRange(2, 5))</var>
</div>
<p>
<span>Captain <var>person(1)</var> has a ship, the H.M.S Crimson Lynx.</span>
<span data-if="isMale(2)">
The ship is <var>DISTANCE</var> furlongs from the dread pirate <var>person(2)</var> and his merciless band of thieves.
</span>
<span data-else="">
The ship is <var>DISTANCE</var> furlongs from the dread pirate <var>person(2)</var> and her merciless band of thieves.
</span>
</p>
<div>
<p data-if="isMale(1)">
If his ship hasn't already been hit, Captain <var>person(1)</var> has probability
<code><var>C_HIT_PRETTY</var></code> of hitting the pirate ship.
If his ship has been hit, Captain <var>person(1)</var> will always miss.
</p><p data-else="">
If her ship hasn't already been hit, Captain <var>person(1)</var> has probability
<code><var>C_HIT_PRETTY</var></code> of hitting the pirate ship.
If her ship has been hit, Captain <var>person(1)</var> will always miss.
</p>
<p data-if="isMale(2)">
If his ship hasn't already been hit, dread pirate <var>person(2)</var> has probability
<code><var>P_HIT_PRETTY</var></code> of hitting the Captain's ship.
If his ship has been hit, dread pirate <var>person(2)</var> will always miss.
</p><p data-else="">
If her ship hasn't already been hit, dread pirate <var>person(2)</var> has probability
<code><var>P_HIT_PRETTY</var></code> of hitting the Captain's ship.
If her ship has been hit, dread pirate <var>person(2)</var> will always miss.
</p>
</div>
<p class="question" data-if="C_FIRST">
If the Captain and the pirate each shoot once, and the Captain shoots first,
what is the probability that <var>QUESTION</var>?
</p><p data-else="">
If the Captain and the pirate each shoot once, and the pirate shoots first,
what is the probability that <var>QUESTION</var>?
</p>
<div class="solution" data-forms="integer, proper, improper, decimal, percent">
<var>ANSWER</var>
</div>
<div class="hints">
<p>
The probability of event A happening, then event B, is the probability of
event A happening times the probability of event B happening
<em>given that event A already happened</em>.
<br><br>
In this case, event A is <var>EV_A</var> and event B is <var>EV_B</var>.
</p>
<p data-if="isMale(C_FIRST ? 1 : 2)">
<span data-if="C_FIRST">
The Captain fires first, so his ship can't be sunk before he fires his cannons.
</span>
<span data-else="">
The pirate fires first, so his ship can't be sunk before he fires his cannons.
</span>
</p>
<p data-else="">
<span data-if="C_FIRST">
The Captain fires first, so her ship can't be sunk before she fires her cannons.
</span>
<span data-else="">
The pirate fires first, so her ship can't be sunk before she fires her cannons.
</span>
</p>
<p>
So, the probability of <var>EV_A</var> is <code><var>PR_A</var></code>.
</p>
<p data-if="PR_B === 0 || PR_B === 1">
<span data-if="C_FIRST">
If the Captain hit the pirate ship, the pirate has no chance of firing back.
</span>
<span data-else="">
If the pirate hit the Captain's ship, the Captain has no chance of firing back.
</span>
</p>
<p data-else="">
<span data-if="C_FIRST">
If the Captain missed the pirate ship, the pirate has a normal chance to fire back.
</span>
<span data-else="">
If the pirate missed the Captain's ship, the Captain has a normal chance to fire back.
</span>
</p>
<p>
So, the probability of <var>EV_B</var> given <var>EV_A</var> is <code><var>PR_B</var></code>.
</p>
<p>
The probability that <var>QUESTION</var> is then the probability of <var>EV_A</var> times
the probability of <var>EV_B</var> given <var>EV_A</var>.
</p>
<p>
This is <code><var>PR_A</var> \cdot <var>PR_B</var>
= <var>fraction(ANS_N, ANS_D, true, true)</var></code>
</p>
</div>
</div>
</div>
</div>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.