STDOUT.sync = true num = "0000000000" (0...10).each{|place| hits = [] (0...10).each{|i| num[place] = i.to_s puts num hit = gets.to_i exit 0 if hit === 10 hits.push([hit, i]) } num[place] = hits.max[1].to_s }