Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- #include <vector>
- inline double fact(double n) {
- if (!n) return 1;
- for (int i = n - 1; i > 0; --i)
- n *= i;
- return n;
- }
- std::vector<double> playerChance ({2/double(3), 1/double(2), 1/double(3), 1/double(4)});
- std::vector<double> enemyChance ({1/double(3), 1/double(2), 2/double(3), 3/double(4)});
- int main() {
- double total = 1;
- for (int i = 0; i < 4; ++i) {
- double base = pow(playerChance[i], 10);
- double runningCount = 0;
- double runChance = 0;
- for (int j = 0; j < 10; ++j) {
- double chances = fact(10+j) / (fact(10) * fact(j));
- chances -= runningCount;
- runningCount += chances;
- double result = base * (pow(enemyChance[i], j));
- runChance += result*chances;
- }
- total *= runChance;
- std::cout << std::fixed << '\n' << runChance << '\n' << total << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement