This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 863
/
dice_probability.html
343 lines (292 loc) · 17.3 KB
/
dice_probability.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!DOCTYPE html>
<html data-require="math math-format graphie word-problems">
<head>
<title>Dice probability</title>
<script src="../khan-exercise.js"></script>
<script type="text/javascript">
KhanUtil.selectMatching = function(matchingPairs) {
$(".e-dice").removeClass("e-selected");
_.each(matchingPairs, function(match) {
$(".e-dice").eq((match[1] - 1) * 6 + (match[0] - 1)).addClass("e-selected");
});
$("#e-selected-count").text($(".e-selected").length);
};
</script>
<style>
/* Classes and IDs are prefixed with "e-" to avoid conflicts with global CSS. */
.e-dice {
background: #d9d9d9;
float: left;
height: 54px;
margin: 0 1px 1px 0;
position: relative;
width: 54px;
}
.e-dice:hover {
background: #def0fa;
}
.e-dice.e-selected {
background: #a9d4eb;
}
.e-die {
background: #333;
border: 1px solid #4d4d4d;
border-radius: 3px;
height: 18px;
position: absolute;
top: 17px;
width: 18px;
}
.e-die.e-black {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGwAAAASCAMAAACJkMtOAAAALVBMVEXMzMxAQEDm5uZzc3OZmZmmpqbZ2dny8vJmZmaAgIBZWVmzs7NNTU3///8zMzMyuWEDAAAA4ElEQVR42s2V4Q6DMAiEdWpbaG/v/7iLTkYrI4saF+9PDX71WiDYPf+oO5gl3ka4eAynLVNkNz3CMK9DeJBrFoDcRjIwWmZ9E1pmlN0FQJwfIoDimCUAaO8lEcvMa1JGI4axZrIt/jDj+tRszFhuvxh0QKjTWOqaTIhk0kjfGYqYWoY+Rehp/cxAfWWWBXC0l7EHUrOCpYSOjjA2sRea2Qa5Oo0B73pOXoOINNciKf6OBsnjCmdpEE/a1ipI5FTrW2murZmth0Z8xjfTUaTSUXR+XFlxMv3GBwfxTX4x1+gFaUFk+Pqj+fIAAAAASUVORK5CYII=');
left: 6px;
}
.e-six-by-four .e-black {
left: 4px;
}
.e-die.e-white {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGwAAAASCAMAAACJkMtOAAAALVBMVEXy8vJmZmZNTU2/v7+ZmZmMjIxZWVlAQEDMzMyzs7PZ2dmAgIDm5uYzMzP///+mxCSnAAAA4UlEQVR42s2V4Q6DIAyEdSrQwu39H3dhsyvYNcs0Lt4fTP3woG3qcP+jrmCWeBvh4jGctkyR3XQLU12ncCPXLAC5j2Rgtsz6JvTMLLsLgFgfIoDimCUA6O8lEcvUNSmjEcNYM9kWv5hxe2o2Ziy3H+s6AqFNY2lrsiCSSSN9Zihi6Rl6F2Gg9TMTDY1ZFsDRDsYcSMwKniV0tIexiT3RzDbI2WkMeNVzsQ3SS3MtkuL/0CB5XuEsDeJJ21oFiRxqfSvNtTWz9dCIz/hmOopUOoqOjysrTqbfeOcgvsgv5hw9AGlBZPiJk4LrAAAAAElFTkSuQmCC');
border-color: #888;
left: 28px;
}
.e-six-by-four .e-die.e-white {
background-color: transparent;
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAAAUCAMAAABF9cjdAAAArlBMVEWIiIiIiIiIiIiIiIiFhYWIiIiBgYGAgICDg4OIiIiIiIiIiIiIiIgAAADc3NyMjIzGxsazs7Nzc3O1tbXBwcHU1NTn5+fw8PCAgIBZWVm/v79AQEBmZmbe3t5NTU3p6emenp68vLzh4eHExMTy8vLm5ubs7Oz29vbQ0NDS0tLj4+P6+vqZmZnx8fGPj4/Ly8va2trMzMz4+PjZ2dl/f3+Xl5empqYzMzOIiIj///+cFc8QAAAADnRSTlNwoFAws2Db7seAIBBAAIeueasAAAG4SURBVHjardJZb5tAFIZhstmOcZvaTVo2k43NMATjAYbv//+xDtucSoOcG87deYTmFdIxfqi5W6/vaFvK/wts6rcNbUs5BW7rC+pbtS7lFFifgPNarQs5BR4byGkep30Zp8C2+kAoytdqOwJ544rDzxnf+8Ka+x6OYJNT4OY3mC9KvN+MoJyLJ8e1dA9cqxGN7ghdwTA4BXZfFzBLBi5fu0GUMwHYnu4hC7nY6w67kYHBKbD5BFDKAIrpxMjRCGfOmfAD3Z8OkIHeKfBQYwqgfuiJPPB8Z8bDEqFv6S5sT/j7zilgVmcKfFRmZ8oD/xBgxhsRwvZ0Z4wJr1Ru0Gl1ATox5Y2Q4+keuK4tHN3lCAblXWDbvvYelAHk/G23EpWHpRyuO4KGhZhxoCTvA/fvQJZDzee9xNFpvvX5d4zhtJAlA6ZFNJ5Y79mRX3c55PQOuQysijzh/OVPjwXyPD2t5PfSkb08x7jqSYQ4G53eIZcBowYHYj4G+C9wvMmu9PQ5jzmuOtKkyCend8iN7rTygn44T5MU58rsPI6i4/EbR8ajyekdcmPXnqDNud0t5Ya5amdmZS7l/wAsNOvj8l2mDQAAAABJRU5ErkJggg==');
border: none;
height: 20px;
left: 26px;
width: 24px;
}
.e-two { background-position: -18px 0; }
.e-three { background-position: -36px 0; }
.e-four { background-position: -54px 0; }
.e-five { background-position: -72px 0; }
.e-six { background-position: -90px 0; }
.e-six-by-four .e-white.e-two { background-position: -24px 0; }
.e-six-by-four .e-white.e-three { background-position: -48px 0; }
.e-six-by-four .e-white.e-four { background-position: -72px 0; }
#e-dice-container {
margin: 0 auto;
width: 330px;
}
#e-dice-container .e-legend {
font-size: 14px;
font-style: italic;
text-align: right;
}
.e-grid {
overflow: hidden; /* clearfix */
}
.e-grid.e-six-by-four { height: 220px; }
.e-grid.e-six-by-six { height: 330px; }
</style>
</head>
<body>
<div class="exercise">
<div class="problems">
<div id="template" data-weight="0">
<div class="vars">
<!-- PRED defined in concrete problem types -->
<var id="GRID_WIDTH">6</var>
<var id="GRID_HEIGHT">randFromArray([4, 6])</var>
<var id="X">randRange(1, GRID_WIDTH)</var>
<var id="Y">randRange(1, GRID_HEIGHT)</var>
<var id="Z">randRange(2, GRID_WIDTH + GRID_HEIGHT)</var>
<var id="MATCHING_PAIRS">(function() {
var pairs = [], i, j;
for (i = 1; i <= GRID_WIDTH; i++) {
for (j = 1; j <= GRID_HEIGHT; j++) {
if (PRED(i, j)) {
pairs.push([i, j]);
}
}
}
return pairs;
})()</var>
<var id="SOLUTION_N">MATCHING_PAIRS.length</var>
<var id="SOLUTION_D">GRID_WIDTH * GRID_HEIGHT</var>
</div>
<div class="question">
<p class="problem">
<span data-if="GRID_HEIGHT === 4" data-unwrap>
You are given two dice to roll. One is black with six sides, the other is white with four sides.
</span>
<span data-else data-unwrap>
You are given two six-sided dice to roll.
</span>
</p>
<p class="question" id="question-statement"></p>
<p class="problem">If it helps, you may select the matching outcomes below. Your selections
aren't checked with your answer:</p>
<div id="e-dice-container" class="problem">
<div class="e-legend"><span id="e-selected-count">0</span> of <var>SOLUTION_D</var> selected</div>
<div class="e-grid">
<div class="e-dice"><div class="e-black e-die"></div><div class="e-die e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-two"></div><div class="e-die e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-three"></div><div class="e-die e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-four"></div><div class="e-die e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-five "></div><div class="e-die e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-six"></div><div class="e-die e-white"></div></div>
<div class="e-dice"><div class="e-black e-die"></div><div class="e-die e-two e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-two"></div><div class="e-die e-two e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-three"></div><div class="e-die e-two e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-four"></div><div class="e-die e-two e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-five "></div><div class="e-die e-two e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-six"></div><div class="e-die e-two e-white"></div></div>
<div class="e-dice"><div class="e-black e-die"></div><div class="e-die e-three e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-two"></div><div class="e-die e-three e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-three"></div><div class="e-die e-three e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-four"></div><div class="e-die e-three e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-five "></div><div class="e-die e-three e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-six"></div><div class="e-die e-three e-white"></div></div>
<div class="e-dice"><div class="e-black e-die"></div><div class="e-die e-four e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-two"></div><div class="e-die e-four e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-three"></div><div class="e-die e-four e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-four"></div><div class="e-die e-four e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-five "></div><div class="e-die e-four e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-six"></div><div class="e-die e-four e-white"></div></div>
<div class="e-dice"><div class="e-black e-die"></div><div class="e-die e-five e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-two"></div><div class="e-die e-five e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-three"></div><div class="e-die e-five e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-four"></div><div class="e-die e-five e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-five "></div><div class="e-die e-five e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-six"></div><div class="e-die e-five e-white"></div></div>
<div class="e-dice"><div class="e-black e-die"></div><div class="e-die e-six e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-two"></div><div class="e-die e-six e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-three"></div><div class="e-die e-six e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-four"></div><div class="e-die e-six e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-five "></div><div class="e-die e-six e-white"></div></div>
<div class="e-dice"><div class="e-black e-die e-six"></div><div class="e-die e-six e-white"></div></div>
</div>
</div>
<div class="graphie problem">
Khan.scratchpad.disable();
// Set .e-grid size.
$('.e-grid').addClass('e-six-by-' + (GRID_HEIGHT === 6 ? 'six' : 'four'));
// Toggle cell selection on click.
var selected = $('#e-selected-count');
$('.e-dice').on('click', function() {
$(this).toggleClass('e-selected');
selected.text($('.e-selected').length);
});
</div>
</div>
<div class="solution" data-type="rational"><var>SOLUTION_N / SOLUTION_D</var></div>
<div class="hints">
<div>
<p>
There <var>plural("is", SOLUTION_N)</var>
<b><var>cardinal(SOLUTION_N)</var></b> matching
<var>plural("outcome", SOLUTION_N)</var>.
</p>
<div class="graphie">
selectMatching(MATCHING_PAIRS);
</div>
</div>
<p>The probability is the number of <b>matching outcomes</b> divided by <b>all possible outcomes</b>.</p>
<p data-if="reduces(SOLUTION_N, SOLUTION_D)">
The probability is <code><var>fraction(SOLUTION_N, SOLUTION_D)</var></code>,
which reduces to <code><var>fractionReduce(SOLUTION_N, SOLUTION_D)</var></code>.
</p>
<p data-else>
The probability is <code><var>fractionReduce(SOLUTION_N, SOLUTION_D)</var></code>.
</p>
</div>
</div>
<div id="d1-and-d2-are-x-and-y" data-type="template">
<div class="vars" data-apply="prependVars">
<var id="PRED">function(x, y) {
return (x === X && y === Y ||
x === Y && y === X);
}</var>
</div>
<span class="question" id="question-statement" data-apply="append">
For a given roll, what is the probability that the dice are
<span data-if="X !== Y">
<code><var>X</var></code> and <code><var>Y</var></code
><span data-if="X < 5"> in any order</span
></span
><span data-else>
both equal to <code><var>X</var></code
></span>?
</span>
</div>
<div id="d1-is-even-d2-is-x" data-type="template">
<div class="vars" data-apply="prependVars">
<var id="EVEN">rand(2)</var>
<var id="EVEN_OR_ODD">EVEN ? "odd" : "even"</var>
<var id="PRED">function(x, y) {
return x % 2 === EVEN && y === Y;
}</var>
</div>
<span class="question" id="question-statement" data-apply="append">
For a given roll, what is the probability that the black die is
<var>EVEN_OR_ODD</var> and the white die is <code><var>Y</var></code>?
</span>
<div class="hints" data-apply="prependContents">
<p>How many <var>EVEN_OR_ODD</var> numbers are there on the black die?</p>
</div>
</div>
<div id="d1-plus-d2-is-x" data-type="template" data-weight="2">
<div class="vars" data-apply="prependVars">
<var id="PRED">function(x, y) {
return x + y === Z;
}</var>
</div>
<span class="question" id="question-statement" data-apply="append">
For a given roll, what is the probability that the dice add to <code><var>Z</var></code>?
</span>
<div class="hints" data-apply="prependContents">
<p>For each value on the black die, is there a value on the white die that adds to <code><var>Z</var></code>?</p>
</div>
</div>
<div id="d1-plus-d2-is-leq-x" data-type="template" data-weight="2">
<div class="vars" data-apply="prependVars">
<var id="PRED">function(x, y) {
return x + y <= Z;
}</var>
</div>
<span class="question" id="question-statement" data-apply="append">
For a given roll, what is the probability that the dice add to <code><var>Z</var></code> <em>or less</em>?
</span>
<div class="hints" data-apply="prependContents">
<p>Count all outcomes that are less than or equal to <code><var>Z</var></code>.</p>
</div>
</div>
<div id="d1-same-as-d2" data-type="template">
<div class="vars" data-apply="prependVars">
<var id="PRED">function(x, y) {
return x === y;
}</var>
</div>
<span class="question" id="question-statement" data-apply="append">
For a given roll, what is the probability you roll the same number on each die?
</span>
</div>
<div id="d1-is-x-d2-is-y" data-type="template">
<div class="vars" data-apply="prependVars">
<var id="PRED">function(x, y) {
return x === X && y === Y;
}</var>
</div>
<span class="question" id="question-statement" data-apply="append">
For a given roll, what is the probability the black die is <code><var>X</var></code> and the white die is <code><var>Y</var></code>?
</span>
</div>
<div id="d1-or-d2-is-x" data-type="template">
<div class="vars" data-apply="prependVars">
<var id="PRED">function(x, y) {
return x === X || y === X;
}</var>
</div>
<span class="question" id="question-statement" data-apply="append">
For a given roll, what is the probability at least one die is <code><var>X</var></code>?
</span>
<div class="hints" data-apply="prependContents">
<p data-if="X < 5">Remember that both dice can be <code><var>X</var></code> ("at least one").</p>
</div>
</div>
</div>
</div>
</body>
</html>