Skip to content

Instantly share code, notes, and snippets.

@wjessop
Last active December 21, 2015 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wjessop/6312444 to your computer and use it in GitHub Desktop.
Save wjessop/6312444 to your computer and use it in GitHub Desktop.
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