1000.times do |i| i = "%03d" % i puts i STDOUT.flush s = gets.strip if s == "unlocked" break end end