aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-02-24 12:45:29 -0600
committerRossTheRoss <msattr@gmail.com>2019-02-24 12:45:29 -0600
commit747ae59bca51bcdad70dc89e9b5bb0578c2e5d68 (patch)
tree93cf164d60d28743e3b8aa83704c921ba519bdf6
parentFinish 3C (diff)
downloadhomework-747ae59bca51bcdad70dc89e9b5bb0578c2e5d68.tar
homework-747ae59bca51bcdad70dc89e9b5bb0578c2e5d68.tar.gz
homework-747ae59bca51bcdad70dc89e9b5bb0578c2e5d68.tar.bz2
homework-747ae59bca51bcdad70dc89e9b5bb0578c2e5d68.tar.lz
homework-747ae59bca51bcdad70dc89e9b5bb0578c2e5d68.tar.xz
homework-747ae59bca51bcdad70dc89e9b5bb0578c2e5d68.tar.zst
homework-747ae59bca51bcdad70dc89e9b5bb0578c2e5d68.zip
Rage at 3A
-rw-r--r--ee1301/wk3/hw3_directory/strap012_HW3A.cpp33
-rw-r--r--project.properties1
2 files changed, 20 insertions, 14 deletions
diff --git a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
index e22ef89..55e8f6c 100644
--- a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
+++ b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
@@ -12,31 +12,38 @@ 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) {
- int spinOG, spinNew;
- spinOG = rand() % d + 1;
- for (int i=1; i<w; i++) {
- spinNew = rand() % d + 1;
- if (spinNew!=spinOG) {
- return 0;
+ int spinOG=0, spinNew=0, win=0;
+ for (int i=1; i<=w; i++) {
+ spinOG = ( (rand() % d) + 1);
+ spinNew = ( (rand() % d) + 1);
+ if (spinOG==spinNew) {
+ win++;
}
}
- return 1;
+ if (win==w) {
+ return 1;
+ } else {
+ return 0;
+ }
}
int main () {
+ srand(time(NULL));
long n = 0;
int m = 0;
- int test;
+ float test;
int w = 3;
int d = 9;
- for (n; n <= 1000; n++)
+ for (n; n <= 1000000; n++)
{
test = spin_the_wheel(d, w);
m+=test;
- }
- cout << "w=" << w << ", d=" << d;
- cout << ": Simulated probability = m/n = " << (m/n)*100 << "%. ";
- cout << "Theoretical probability = " << (d/(pow(d,w)))*100 << "%." << endl;
+ }
+
+ cout << "w=" << w << ", d=" << d;
+ cout << ": Simulated probability = m/n = " << (m/n)*100 << "%. ";
+ cout << "Theoretical probability = " << (d/(pow(d,w)))*100 << "%." << endl;
} \ No newline at end of file
diff --git a/project.properties b/project.properties
deleted file mode 100644
index d2afcd3..0000000
--- a/project.properties
+++ /dev/null
@@ -1 +0,0 @@
-name=Test