Created
August 16, 2020 11:45
-
-
Save Hendekagon/605053e81fe25ba3ae02d9e78cb04fc9 to your computer and use it in GitHub Desktop.
economy-dw
This file contains hidden or 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
; 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