Created
July 29, 2017 00:42
-
-
Save odeblic/2a40e325908f8faac67c860bdb3a0a31 to your computer and use it in GitHub Desktop.
Head or tail prediction
This file contains hidden or 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 <ctime> | |
| inline bool randomBool() | |
| { | |
| return rand() % 2; | |
| } | |
| int heads = 0; | |
| int tails = 0; | |
| int right = 0; | |
| int wrong = 0; | |
| int main() | |
| { | |
| srand(time(NULL)); | |
| while(heads + tails < 10000) | |
| { | |
| bool draw = randomBool(); | |
| if(heads != tails) | |
| { | |
| bool pre_draw = heads < tails; | |
| if(draw == pre_draw) | |
| { | |
| right++; | |
| } | |
| else | |
| { | |
| wrong++; | |
| } | |
| } | |
| //std::cout << "draw : " << (draw ? "heads" : "tails") << std::endl; | |
| if(draw) | |
| { | |
| heads++; | |
| } | |
| else | |
| { | |
| tails++; | |
| } | |
| } | |
| std::cout << "draws : " << heads + tails << std::endl; | |
| std::cout << "heads : " << heads << std::endl; | |
| std::cout << "tails : " << tails << std::endl; | |
| std::cout << std::endl; | |
| std::cout << "tries : " << right + wrong << std::endl; | |
| std::cout << "right : " << right << std::endl; | |
| std::cout << "wrong : " << wrong << std::endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment