Skip to content

Instantly share code, notes, and snippets.

@ghiden
Last active August 29, 2015 14:23
Show Gist options
  • Save ghiden/a4d7b9f25c296edc6010 to your computer and use it in GitHub Desktop.
Save ghiden/a4d7b9f25c296edc6010 to your computer and use it in GitHub Desktop.
#!/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
# print
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