Skip to content

Instantly share code, notes, and snippets.

@gasin
Created January 14, 2022 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gasin/dab543154c2b38843fd0073d19230374 to your computer and use it in GitHub Desktop.
Save gasin/dab543154c2b38843fd0073d19230374 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
int calc_bonus(int streak) {
if (streak == 2 || streak == 3) {
return 1;
} else if (streak == 4) {
return 2;
} else if (streak >= 5) {
return 3;
}
return 0;
}
void calc_expected_bonus (int id, int count, int streak, int prev, std::vector<std::pair<double,int>>& stage) {
double expected_count = 0.0;
for (int i = 0; i < (1<<3); i++) {
int _count = 0, _streak = streak, _prev = prev;
for (int j = 0; j < 3; j++) {
int result = (i>>j) % 2;
if (result == 1) {
_count++;
}
if (_prev == result) {
_streak++;
} else {
_streak = 1;
}
_count += calc_bonus(_streak);
_prev = result;
}
expected_count += _count;
}
expected_count /= (1<<3);
stage.push_back(std::make_pair(count+expected_count,id));
}
int main() {
std::vector<std::pair<int,int>> stage2;
std::vector<std::pair<double,int>> stage3;
for (int i = 0; i < (1<<5); i++) {
int count = 0, streak = 0;
int prev = -1;
for (int j = 0; j < 5; j++) {
int result = (i>>j) % 2;
if (result == 1) {
count++;
}
if (prev == result) {
streak++;
} else {
streak = 1;
}
prev = result;
count += calc_bonus(streak);
}
count += calc_bonus(streak);
stage2.push_back(std::make_pair(count,i));
calc_expected_bonus(i, count, streak, prev, stage3);
}
std::sort(stage2.rbegin(), stage2.rend());
std::sort(stage3.rbegin(), stage3.rend());
std::cout << "stage2" << std::endl;
for (auto p : stage2) {
for (int i = 0; i < 5; i++) {
if ((p.second >> i) % 2) {
std::cout << "o";
} else {
std::cout << "x";
}
}
std::cout << " " << p.first << std::endl;
}
std::cout << "stage3" << std::endl;
for (auto p : stage3) {
for (int i = 0; i < 5; i++) {
if ((p.second >> i) % 2) {
std::cout << "o";
} else {
std::cout << "x";
}
}
std::cout << " " << p.first << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment