Skip to content

@henrik /scheduler.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Scheduler - cleaned up version of Evgeny Kluev's solution http://stackoverflow.com/a/11761192/6962
class Scheduler
def initialize
@schedule = []
@word = 0
end
def next_slot
if @schedule.empty?
slot = 0
else
bit = 32
while (((@word ^= bit) & bit) == 0) do
bit >>= 1;
end
slot = (@word * 60) / 64
end
@schedule << slot
@schedule.sort!
slot
end
def schedule
@schedule
end
end
scheduler = Scheduler.new
60.times do
scheduler.next_slot
p scheduler.schedule
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.