Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
6
Indexable
Never
#include <cstdio>
#include <vector>

#include <random>

const int rand_prob_space = 10;
const int SAMPLE_SIZE = 10'000'000;
const char labels[7] = {'0', '1', '2', '3', '4', '5', '6'};

std::random_device                  r;
std::mt19937                        gen(r());
std::uniform_int_distribution<int>  d(0, rand_prob_space - 1);

/// will move triplets 1 pos mod 10 and sort them out
void arrange(int* t)
{
	int a = (t[0] + 1)%10;
	int b = (t[1] + 1)%10;
	int c = (t[2] + 1)%10;

	if (a > b) {
		int buff = b;
		b = a;
		a = buff;
	}

	if (b > c) {
		int buff = c;
		c = b;
		b = buff;
		if (a > b) {
			int buff = b;
			b = a;
			a = buff;
		}
	}

	t[0] = a;
	t[1] = b;
	t[2] = c;
}

int main()
{
	int t[3] = {0,1,2};

	std::vector<char> dist;
	dist.reserve(SAMPLE_SIZE);

	for (int i = 0; i < SAMPLE_SIZE; ++i) {
		int num = d(gen);
		if (num == t[0] || num == t[1] || num == t[2] ) {
			arrange(t);
		} else {
			char c;
			int shift = 0;

			if (t[0] < num) ++shift;
			if (t[1] < num) ++shift;
			if (t[2] < num) ++shift;

			int idx = num - shift;

			c = labels[idx];
						
			dist.push_back(c);
		}
	}

	int stats[7] = {};

	for (auto var : dist) {
		if (var == '0'){ stats[0] += 1; continue; }
		if (var == '1'){ stats[1] += 1; continue; }
		if (var == '2'){ stats[2] += 1; continue; }
		if (var == '3'){ stats[3] += 1; continue; }
		if (var == '4'){ stats[4] += 1; continue; }
		if (var == '5'){ stats[5] += 1; continue; }
		if (var == '6'){ stats[6] += 1; continue; }
	}

	for (int i = 0; i < 7; ++i) {
		printf("%c: %d\n",i+48,stats[i]);
	}

	printf("dist vector size: %d\n", dist.size());

	return 0;
}