Created
November 27, 2011 14:56
-
-
Save LCamel/1397659 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
const int N = 49; | |
const int M = 7; | |
long long l(const long long n, const int i) { // left | |
return (i == M - 1) ? n : l(n, i + 1) / (N - (i + 1)); | |
} | |
int b(const long long n, const int i) { //branch | |
return (int) (l(n, i) % (N - i)); | |
} | |
int p(const long long n, const int i); | |
int u(const long long n, const int i, const int j) { // used | |
int s = 0; | |
for (int k = 0; k < i; k++) | |
if (p(n, k) <= j) | |
s++; | |
return s; | |
} | |
int p(const long long n, const int i) { // permutation | |
const int b0 = b(n, i); | |
for (int j = b0; j < N; j++) | |
if (u(n, i, j) + b0 == j) | |
return j; | |
} | |
int main(void) { | |
srand((unsigned int) time(NULL)); | |
unsigned long long n = (0LL + rand()) << 32 | rand(); | |
n %= 49LL * 48 * 47 * 46 * 45 * 44 * 43; | |
for (int i = 0; i < M; i++) | |
printf("%d ", p(n, i) + 1); | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment