$stdout.sync = true S = "XXXXXXXXXX" ans = S.dup for c in "0".."9" do for i in 0..9 do s = S.dup s[i] = c puts s res = gets ans[i] = c if res[/\d+/].to_i > 0 end end puts ans