Created
January 11, 2018 08:30
-
-
Save mather/e3fc196b265582b176a33e2ee2e49f92 to your computer and use it in GitHub Desktop.
ランダム選ばれた二人がコインを渡し合うとどうなるか
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
INITIAL_COINS = 0 | |
NUMBER_OF_MEMBER = 100 | |
NUMBER_OF_TRIAL = 10_000_000 | |
members = Array.new(NUMBER_OF_MEMBER) { |i| INITIAL_COINS } | |
NUMBER_OF_TRIAL.times do |n| | |
if n % 100_000 == 0 | |
puts n.to_s + "\t" + members.map(&:to_s).join("\t") | |
end | |
from = rand(NUMBER_OF_MEMBER) | |
to = rand(NUMBER_OF_MEMBER) | |
move_coins = 1 | |
# 徐々にインフレするケース(桃鉄?) | |
# move_coins = (10**(n*1.0/NUMBER_OF_TRIAL)).floor | |
members[from] -= move_coins | |
members[to] += move_coins | |
end | |
puts NUMBER_OF_TRIAL.to_s + "\t" + members.map(&:to_s).join("\t") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment