Skip to content

Instantly share code, notes, and snippets.

@macterra
Last active July 19, 2017 22:48
Show Gist options
  • Save macterra/01850b02356566a671dd2bc9ac9d5764 to your computer and use it in GitHub Desktop.
Save macterra/01850b02356566a671dd2bc9ac9d5764 to your computer and use it in GitHub Desktop.
import random
def hist(x):
h = [0 for i in range(11)]
band = x[N-1]/10.0
for i in range(N):
dec = (int)(x[i]/band)
h[dec] = h[dec] + 1
return h
N = 100 # population size
W = 100 # initial wealth
I = 1000 # number of iterations
x = [W for i in range(N)]
for i in range(I):
x.sort()
print i
print x
print hist(x)
print "-" * 60
for j in range(N):
if x[j] > 0:
k = random.randint(0, N-1)
x[k] = x[k] + 1
x[j] = x[j] - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment