defmodule Main do def input, do: IO.read(:line) |> String.trim def ii, do: input() |> String.to_integer def li, do: input() |> String.split |> Enum.map(&String.to_integer/1) def yn(b), do: IO.puts(if b, do: "Yes", else: "No") def main do m = for i <- 0..9, into: %{}, do: {i, 0} f(0, m) end def f(p, m) do {i, _} = for i <- 0..9, reduce: {-1, -1} do {q, ma} -> m2 = Map.update!(m, p, fn _ -> i end) same = query(m2) if same == 10, do: System.halt() cond do same > ma -> {i, same} true -> {q, ma} end end m2 = Map.update!(m, p, fn _ -> i end) f(p+1, m2) end def query(m) do put(m) read() end def read() do [x, _msg] = input() |> String.split String.to_integer(x) end def put(m) do Map.values(m) |> Enum.join() |> IO.puts end end