Skip to content

Instantly share code, notes, and snippets.

@Hendekagon
Created August 16, 2020 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hendekagon/605053e81fe25ba3ae02d9e78cb04fc9 to your computer and use it in GitHub Desktop.
Save Hendekagon/605053e81fe25ba3ae02d9e78cb04fc9 to your computer and use it in GitHub Desktop.
economy-dw
; https://www.scientificamerican.com/article/is-inequality-inevitable/
; https://threadreaderapp.com/thread/1210332075787608065.html
(defn economy-dw
"
Simulate one round of
random transfers of wealth
between the given agents' accounts
(a vector of initial amounts)
e.g.
(last (take 1000 (iterate economy-dw (vec (repeat 1000 100)))))
view histogram with Incanter:
(ic/view (ih/histogram (last (take 1000 (iterate economy-dw (vec (repeat 1000 100)))))))
"
([agents]
(economy-dw {} (vec agents)))
([{:keys [wdw ldw] :or {wdw 0.2 ldw -0.17}} agents]
(reduce
(fn [r x]
(let [y (rand-int (count r))
[a b] (if (< (r x) (r y)) [x y] [y x])
c (== 1 (rand-int 2))
dw (* (r a) (if c wdw ldw))]
(-> r (update a + dw) (update b - dw))))
agents (range (count agents)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment