Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Scheduler - cleaned up version of Evgeny Kluev's solution http://stackoverflow.com/a/11761192/6962

View scheduler.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
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.