Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
56
Task/100-prisoners/Processing/100-prisoners.processing
Normal file
56
Task/100-prisoners/Processing/100-prisoners.processing
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
IntList drawers = new IntList();
|
||||
int trials = 100000;
|
||||
int succes_count;
|
||||
|
||||
void setup() {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
drawers.append(i);
|
||||
}
|
||||
println(trials + " trials\n");
|
||||
|
||||
//Random strategy
|
||||
println("Random strategy");
|
||||
succes_count = trials;
|
||||
for (int i = 0; i < trials; i++) {
|
||||
drawers.shuffle();
|
||||
for (int prisoner = 0; prisoner < 100; prisoner++) {
|
||||
boolean found = false;
|
||||
for (int attempt = 0; attempt < 50; attempt++) {
|
||||
if (drawers.get(int(random(drawers.size()))) == prisoner) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
succes_count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
println(" Succeses: " + succes_count);
|
||||
println(" Succes rate: " + 100.0 * succes_count / trials + "%\n");
|
||||
|
||||
//Optimal strategy
|
||||
println("Optimal strategy");
|
||||
succes_count = trials;
|
||||
for (int i = 0; i < trials; i++) {
|
||||
drawers.shuffle();
|
||||
for (int prisoner = 0; prisoner < 100; prisoner++) {
|
||||
boolean found = false;
|
||||
int next = prisoner;
|
||||
for (int attempt = 0; attempt < 50; attempt++) {
|
||||
next = drawers.get(next);
|
||||
if (next == prisoner) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
succes_count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
println(" Succeses: " + succes_count);
|
||||
print(" Succes rate: " + 100.0 * succes_count / trials + "%");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue