Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- #intuitive reason is that 0.95*1.05 = 0.99749, so that's the odd, if you play always 5% on a fair coin,
- #the best strategy then is to play less % as possible, and this happens for the rich,
- #that match the % of the poor, that % beeing for him less (in %)
- #https://www.scientificamerican.com/article/is-inequality-inevitable/
- def generate_oligarchy(time):
- def choose_ppl():
- result = -1
- while result <= 0:
- pick = random.randint(0, len(ppl)-1)
- result = ppl[pick]
- return pick
- ppl = [100.]*1000 #at the beginning there are 1000 persons with 100 coins
- for t in range(time):
- a = choose_ppl()
- b = choose_ppl()
- bet = min(a, b)*.05 #the poorer bet 5% on a coin flip, the richer match the bet
- if random.random() >= 0.5:
- ppl[a] += bet
- ppl[b] -= bet
- else:
- ppl[a] -= bet
- ppl[b] += bet
- ppl.sort()
- ppl = ppl[::-1]
- print time
- return ppl
- x = 0
- for t in range(1,7):
- ppl = generate_oligarchy(10**t)
- open('gini_'+str(x), 'w').write('\n'.join(map(str, ppl)))
- print '''gnuplot -p -e "set yrange [0:1000]; plot 'gini_1' w l; replot 'gini_2' w l; replot 'gini_3' w l; replot 'gini_4' w l; replot 'gini_5' w l; replot 'gini_6' w l; replot 'gini_7' w l; replot 'gini_8' w l; set term png size 900,700; set output 'gini.png'; replot; pause mouse close"'''
Advertisement
Add Comment
Please, Sign In to add comment