public int findPattern (int times, int a, int b, int c) {
int finds = 0;
List m = new ArrayList();
for (int i = 0; i < times; i++) {
int x = (int)Math.floor(Math.random()*2);
if (m.size() == 0) {
if (x == a)
m.add(a);
else {
m.clear();
continue;
}
} else if (m.size() == 1) {
if (x == b)
m.add(b);
else {
m.clear();
continue;
}
} else if (m.size() == 2) {
if (x == c)
finds++;
m.clear();
}
}
return finds;
}
public static void main(String[] args) {
CoinFlip cf = new CoinFlip();
System.out.println("HTH: " + cf.findPattern(1000000, 1, 0, 1));
System.out.println("HTT: " + cf.findPattern(1000000, 1, 0, 0));
}
}
Results of running it 3 times: HTH: 71499 HTT: 71070