aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-02-25 17:04:29 +0000
committerRossTheRoss <msattr@gmail.com>2019-02-25 17:04:29 +0000
commitfe474aa63f0751a48899121d461f47f0f0bcb1f6 (patch)
tree07d5803b28542f8195d6c159cb82b746436b2ec8
parentFinish 3A but 10s are hard (diff)
downloadhomework-fe474aa63f0751a48899121d461f47f0f0bcb1f6.tar
homework-fe474aa63f0751a48899121d461f47f0f0bcb1f6.tar.gz
homework-fe474aa63f0751a48899121d461f47f0f0bcb1f6.tar.bz2
homework-fe474aa63f0751a48899121d461f47f0f0bcb1f6.tar.lz
homework-fe474aa63f0751a48899121d461f47f0f0bcb1f6.tar.xz
homework-fe474aa63f0751a48899121d461f47f0f0bcb1f6.tar.zst
homework-fe474aa63f0751a48899121d461f47f0f0bcb1f6.zip
A hack is the best kind of fix
-rw-r--r--ee1301/wk3/hw3_directory/strap012_HW3A.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
index 8d75294..e9701ff 100644
--- a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
+++ b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
@@ -12,7 +12,6 @@ One-armed Bandit Simulator
#include <stdlib.h>
#include <cmath>
#include <iomanip>
-#include <time.h>
using namespace std;
int spin_the_wheel(int d, int w) {
@@ -21,7 +20,7 @@ int spin_the_wheel(int d, int w) {
for (int i=0; i<w; i++) {
spinOG = ( (rand() % d) + 1);
spinNew = ( (rand() % d) + 1);
- if (spinOG==spinNew) {
+ if (spinOG==spinNew) {
win++;
}
}
@@ -33,20 +32,19 @@ int spin_the_wheel(int d, int w) {
}
int main () {
- srand(10000);
+ srand(88888888); //See
int w, d, m, test;
for (w=3; w<=6; w++) {
m=0;
for (d=9; d<=27; d++) {
m=0;
- for (long n=1000000; n>0; n--) {
+ for (long long n=1000000; n>0; n--) {
int test = spin_the_wheel(d, w);
m+=test;
}
double win=m;
- cout << fixed << setprecision(5)
- << "w=" << w << ", d=" << d
- << ": Simulated probability = m/n = " << (win / 1000000.0) * 100.0 << "%. "
+ cout << "w=" << w << ", d=" << d
+ << ": Simulated probability = m/n = " << (win / 100000.0) * 100.0 << "%. "
<< "Theoretical probability = " << (d / (pow(d, w))) * 100 << "%." << endl;
d+=2;
}