Last active
June 27, 2017 04:16
-
-
Save szilard/611e11be34f6ff247b45644a0fc803bb 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 100 | |
#define B0 100 | |
#define R 1000000 | |
int main() { | |
int b[N], rec[N]; | |
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]]++; | |
} | |
for (int i=0; i<N; i++) printf("%d ",b[i]); | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment