Skip to content

Instantly share code, notes, and snippets.

@szilard
Last active June 27, 2017 04:16
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 szilard/611e11be34f6ff247b45644a0fc803bb to your computer and use it in GitHub Desktop.
Save szilard/611e11be34f6ff247b45644a0fc803bb to your computer and use it in GitHub Desktop.
#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