forked from Adespinoza/daily-coding-problem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem_178.js
46 lines (39 loc) Β· 1000 Bytes
/
problem_178.js
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
// It doesn't matter which game Alice elects to play because her probability of
// rolling die1 and landing on 5 is independent from wether she lands on 5 or 6
// on die2.
/**
* Stop rolling once you get a five followed by a six.
* @return {number} count of rolls/dues
*/
function rollDifferentNums() {
let count = 0;
let die1;
let die2;
while (die1 !== 5 && die2 !== 6) {
// roll dice
die1 = Math.floor(1 + Math.random() * 6);
die2 = Math.floor(1 + Math.random() * 6);
// increase count
count += 1;
}
return count;
}
/**
* Stop rolling once you get a five followed by a five.
* @return {number} count of rolls/dues
*/
function rollSameNums() {
let count = 0;
let die1;
let die2;
while (die1 !== 5 && die2 !== 5) {
// roll dice
die1 = Math.floor(1 + Math.random() * 6);
die2 = Math.floor(1 + Math.random() * 6);
// increase count
count += 1;
}
return count;
}
console.log(rollDifferentNums());
console.log(rollSameNums());