Skip to content

Instantly share code, notes, and snippets.

@avibryant
Last active September 29, 2015 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save avibryant/1624661 to your computer and use it in GitHub Desktop.
Save avibryant/1624661 to your computer and use it in GitHub Desktop.
require 'date'
DUE_DATE = "2013-05-19"
#data taken from http://spacefem.com/pregnant/charts/duedate2.php
#starts at day 222
DATA = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 2, 1, 4, 2, 2, 1, 4, 6, 7, 5, 1, 5, 8, 7, 9, 10, 11, 13, 13, 18,
14, 13, 9, 27, 29, 27, 31, 27, 26, 36, 43, 43, 51, 67, 74, 60, 47,
41, 44, 36, 37, 48, 30, 20, 22, 24, 16, 11, 12, 8, 4, 2, 0, 1, 0, 1
]
start_index = Date.today + 58 - Date.parse(DUE_DATE)
frequencies = DATA[start_index .. -1]
acc = 0
cumulative_frequencies = frequencies.map{|n| acc += n}
cumulative_probabilities = cumulative_frequencies.map{|n| n.to_f / cumulative_frequencies[-1]}
puts "Chance of baby"
cumulative_probabilities.each_with_index do |prob, i|
puts "by #{(Date.today + i).to_s}: #{(prob*100).to_i}%"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment