pietrod21

ginibets

Apr 3rd, 2021
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import random
  2.  
  3. #intuitive reason is that 0.95*1.05 = 0.99749, so that's the odd, if you play always 5% on a fair coin,
  4. #the best strategy then is to play less % as possible, and this happens for the rich,
  5. #that match the % of the poor, that % beeing for him less (in %)  
  6. #https://www.scientificamerican.com/article/is-inequality-inevitable/
  7.  
  8. def generate_oligarchy(time):
  9.     def choose_ppl():
  10.         result = -1
  11.         while result <= 0:
  12.             pick = random.randint(0, len(ppl)-1)
  13.             result = ppl[pick]
  14.         return pick
  15.  
  16.     ppl = [100.]*1000 #at the beginning there are 1000 persons with 100 coins
  17.     for t in range(time):
  18.         a = choose_ppl()
  19.         b = choose_ppl()
  20.         bet = min(a, b)*.05 #the poorer bet 5% on a coin flip, the richer match the bet
  21.         if random.random() >= 0.5:
  22.             ppl[a] += bet
  23.             ppl[b] -= bet
  24.         else:
  25.             ppl[a] -= bet
  26.             ppl[b] += bet
  27.  
  28.     ppl.sort()
  29.     ppl = ppl[::-1]
  30.     print time
  31.     return ppl
  32.  
  33. x = 0
  34. for t in range(1,7):
  35.     ppl = generate_oligarchy(10**t)
  36.     open('gini_'+str(x), 'w').write('\n'.join(map(str, ppl)))
  37.  
  38. 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