Created
September 16, 2015 22:38
-
-
Save workmad3/d1013f6e22e7c04889f4 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
mem, *processes = ARGV.map(&:to_i) | |
rates = processes.map{|i| Rational(1, i)} | |
def memory_for_second(second, processes) | |
processes.reduce(0) {|sum, process| sum + (second / process)} | |
end | |
def minimum_second(mem, rates) | |
(mem / rates.reduce(&:+) ).floor | |
end | |
current_tick = minimum_second(mem, rates) | |
used_memory = memory_for_second(current_tick, processes) | |
while used_memory < mem | |
current_tick += 1 | |
used_memory = memory_for_second(current_tick, processes) | |
end | |
puts "Process count: #{processes.size}" | |
puts "Total memory: #{mem}" | |
puts "Memory used up: #{current_tick}s" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment