Last active
July 19, 2017 22:48
-
-
Save macterra/01850b02356566a671dd2bc9ac9d5764 to your computer and use it in GitHub Desktop.
Simulation to explore https://twitter.com/juliagalef/status/887414654401630208
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
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