Last active
February 8, 2020 16:34
-
-
Save bharddwaj/3096f8c5c5cad132254d9d8a2b33986d to your computer and use it in GitHub Desktop.
Trying to calculate the true probability of getting a 9 with "Judge" on Game and Watch from Super Smash Bros Ultimate. Each number is equally likely to appear (9 possibilities so 1/9 for a 9), but no number can appear twice in a row. I ran some simulations and it seems to me like that there is a 11.1% chance of getting a 9.
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
// | |
// main.cpp | |
// GameAndWatch | |
// | |
// Created by Bharddwaj Vemulapalli on 2/7/20. | |
// Copyright © 2020 Bharddwaj Vemulapalli. All rights reserved. | |
// | |
#include <iostream> | |
#include <random> | |
#include <unordered_map> | |
#include <vector> | |
int main(int argc, const char * argv[]) { | |
std::cout << "Hello, World!\n"; | |
std::vector<double> probabilities = {}; | |
for (int j = 0 ; j < 10; j++) { | |
std::cout << j << std::endl; | |
std::random_device dev; | |
std::mt19937 rng(dev()); | |
std::uniform_int_distribution<std::mt19937::result_type> dist9(1,9); // distribution in range [1, 9] | |
int num = dist9(rng); | |
int prev = 1; | |
std::vector<int> v = {}; | |
for (int i = 0; i < 1000000; i++) { | |
while (num != prev) { | |
std::random_device dev; | |
std::mt19937 rng(dev()); | |
std::uniform_int_distribution<std::mt19937::result_type> dist9(1,9); // distribution in range [1, 9] | |
num = dist9(rng); | |
} | |
std::random_device dev; | |
std::mt19937 rng(dev()); | |
std::uniform_int_distribution<std::mt19937::result_type> dist9(1,9); // distribution in range [1, 9] | |
num = dist9(rng); | |
v.push_back(num); | |
prev = num; | |
} | |
std::unordered_map<int, int> u = { | |
{1,0}, | |
{2,0}, | |
{3,0}, | |
{4,0}, | |
{5,0}, | |
{6,0}, | |
{7,0}, | |
{8,0}, | |
{9,0} | |
}; | |
for (int i = 0; i < v.size(); i++) { | |
u[v[i]] += 1; | |
//std::cout << v[i]; | |
} | |
probabilities.push_back((double)(u[9])/v.size()); | |
} | |
std::cout << "Now for printing out the probabilities" << std::endl; | |
for(int k = 0; k < probabilities.size();k++){ | |
std::cout <<probabilities[k] << std::endl; | |
} | |
return 0; | |
} | |
//0.111182 | |
//0.111793 | |
//0.110979 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment