Last active
August 29, 2015 14:23
-
-
Save ghiden/a4d7b9f25c296edc6010 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
#!/usr/bin/env ruby | |
if ARGV.length != 3 | |
puts 'Need 3 arguments' | |
puts ' calculate-email-distribution INITIAL_SIZE STEP AMOUNT' | |
puts 'e.g.' | |
puts ' calculate-email-distribution 100 20 65000' | |
exit 0 | |
end | |
initialSize = ARGV[0].to_i | |
step = ARGV[1].to_i | |
amount = ARGV[2].to_i | |
header = "Time\tEmails\tTotal\n" | |
puts header | |
a = [initialSize] | |
total = 0 | |
i = 0 | |
loop do | |
a.push(a[i] + step) | |
break if a.inject(0) {|sum, n| sum + n} >= amount | |
i += 1 | |
end | |
sum = 0 | |
a.length.times do |i| | |
sum += a[i] | |
hour = (i + 12) % 24 | |
puts "#{hour}\t#{a[i]}\t#{sum}" | |
puts "\n#{header}" if hour == 23 | |
end | |
# summary | |
daysItTakes = a.length / 24 | |
hoursItTakes = a.length % 24 | |
if daysItTakes > 0 | |
puts "It takes #{daysItTakes} day(s) and #{hoursItTakes} hour(s)." | |
else | |
puts "It takes #{hoursItTakes} hour(s)." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment