-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb.java
More file actions
41 lines (38 loc) · 684 Bytes
/
Prob.java
File metadata and controls
41 lines (38 loc) · 684 Bytes
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
import java.util.HashSet;
import java.util.Set;
public class Prob {
public static void main(String[] args){
int failures = 0;
Set<String> ss = new HashSet<String>();
for (int k = 0; k < 10000000; k++){
int trial = 1;
String s = "";
boolean fail = false;
int dollars = 3;
while (trial <=13){
double r = Math.random();
if (r<=.25){
dollars--;
s+="L";
}
else{
dollars++;
s+="W";
}
if (dollars == 0)
{
fail = true;
break;
}
trial++;
}
if (fail&&trial==5){
failures++;
ss.add(s);
}
}
System.out.println(ss);
System.out.println(ss.size());
System.out.println(failures/10000000.0);
}
}