defmodule Main do def main do IO.read(:line) |> solve |> IO.puts() end defp solve(s) do s |> String.to_charlist() |> count_tre([0, 0, 0]) |> Enum.min() end defp count_tre(s, [t, r, e]) do cond do Enum.empty?(s) -> [t, r, e |> div(2)] true -> tl(s) |> count_tre( cond do hd(s) == ?t -> [t + 1, r, e] hd(s) == ?r -> [t, r + 1, e] hd(s) == ?e -> [t, r, e + 1] true -> [t, r, e] end ) end end end