Skip to content

Instantly share code, notes, and snippets.

@mather
Created January 11, 2018 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mather/e3fc196b265582b176a33e2ee2e49f92 to your computer and use it in GitHub Desktop.
Save mather/e3fc196b265582b176a33e2ee2e49f92 to your computer and use it in GitHub Desktop.
ランダム選ばれた二人がコインを渡し合うとどうなるか
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