Last active
December 21, 2015 13:28
-
-
Save wjessop/6312444 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
require 'thread' | |
LAST_VAL = 8 | |
q = Queue.new | |
(0..LAST_VAL).to_a.shuffle.each {|i| q << i} | |
vals = [] | |
next_val = 0 | |
loop do | |
puts "popping the stack" | |
vals << q.pop | |
vals.sort! | |
puts "vals is now #{vals.inspect}" | |
while vals[0] == next_val | |
puts "Processing #{vals.shift}" | |
next_val += 1 | |
end | |
break if next_val > LAST_VAL | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment