i = 0 key = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] prev = nil now = 0 loop do puts key.join STDOUT.flush a, s = gets.split(' ') break if s == "unlocked" if prev.nil? prev = a elsif prev > a key[now] = (key[now]+9)%10 now += 1 elsif prev < a now += 1 end prev = a key[now] = (key[now]+1)%10 end