Last active
August 29, 2015 14:05
-
-
Save nehalist/1ab1602223ba1ef3bf09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
#include <time.h> | |
class RandomNumberGenerator { | |
public: | |
bool found; | |
int tries; | |
int current; | |
RandomNumberGenerator() { | |
this->tries = 0; | |
this->found = false; | |
// Seed that shit | |
srand(time(NULL)); | |
} | |
void start() { | |
int rnd = (rand() % 100 + 1); | |
this->current = rnd; | |
if(rnd == 1) { | |
this->found = true; | |
} | |
this->tries++; | |
} | |
void reset() { | |
this->found = false; | |
this->tries = 0; | |
this->current = 0; | |
} | |
}; | |
int main() { | |
RandomNumberGenerator rng; | |
/*do { | |
rng.start(); | |
std::cout << "Current: " << rng.current << std::endl; | |
if(rng.found) { | |
std::cout << "Found after " << rng.tries << " tries" << std::endl; | |
} | |
} while( ! rng.found); */ | |
long long iterations = 0; | |
int highest_streak = 0; | |
do { | |
iterations++; | |
rng.start(); | |
for(int i = 1; i <= 1673; i++) { | |
if(rng.found) { | |
std::cout << "Found after " << rng.tries << std::endl; | |
if(rng.tries > highest_streak) { | |
highest_streak = rng.tries; | |
} | |
// ------------------- | |
std::cout << "Highest streak so far: " << highest_streak << std::endl; | |
system("CLS"); | |
// ------------------- | |
rng.reset(); | |
break; | |
} | |
} | |
} while(rng.tries != 1673); | |
std::cout << "Unlucky streak after " << iterations << " iterations" << std::endl; | |
// bad practise, but who cares... | |
system("PAUSE"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment