Last active
June 27, 2017 04:17
-
-
Save szilard/4eafd9d7db61b0e4113d72c7c7d6bb17 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> | |
#define N 128 | |
#define B0 100 | |
#define R 1000000 | |
#define M 1000 | |
int cmpfunc (const void * a, const void * b) | |
{ | |
return ( *(int*)a - *(int*)b ); | |
} | |
int main() { | |
int b[N], rec[N]; | |
double bb[N]; | |
for(int i=0; i<N; i++) bb[i] = 0; | |
for (int m=0; m<=M; m++) { | |
for (int i=0; i<N; i++) b[i] = B0; | |
for (int k=0; k<R; k++) { | |
int Nrec=0; | |
for (int i=0; i<N; i++) { | |
if(b[i]>0) { | |
int r = rand() % (N-1); /* TODO: need better rand gen */ | |
rec[Nrec++] = r<i ? r:r+1; /* can't give to himself */ | |
} | |
} | |
for (int i=0; i<N; i++) if(b[i]>0) b[i]--; | |
for (int j=0; j<Nrec; j++) b[rec[j]]++; | |
} | |
qsort(b, N, sizeof(int), cmpfunc); | |
for(int i=0; i<N; i++) bb[i]+=b[i]; | |
} | |
for (int i=0; i<N; i++) bb[i]/=M; | |
for (int i=0; i<N; i++) printf("%.3f ",bb[i]); | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment