Skip to content

Instantly share code, notes, and snippets.

@jiangplus
Created April 19, 2015 09:21
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 jiangplus/7f985cc427db5efe0a53 to your computer and use it in GitHub Desktop.
Save jiangplus/7f985cc427db5efe0a53 to your computer and use it in GitHub Desktop.
population_dynamics
# testing the 'rand' function
# sum = 0
# 10000.times {
# sum += rand(2)
# }
# puts sum
list = []
100000.times do
family = []
family.push(rand(2)) until family.last == 1
list << family
end
population = list.flatten
sum = population.inject(&:+)
puts "population: #{population.length}"
puts "male: #{sum}"
puts "female: #{population.length - sum}"
puts "f/m ratio: #{(population.length - sum) / sum.to_f}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment