defmodule Main do def main do input_solve() |> IO.puts() end def input_solve() do input_solve_rec([0, 0, 0]) |> (fn [a, b, c] -> [a, b, c |> div(2)] end).() |> Enum.min() end def input_solve_rec(result) do case IO.read(1000) do :eof -> result s -> input_solve_rec(count_tre(s |> String.to_charlist(), result)) end end defp count_tre([], [t, r, e]) do [t, r, e] end defp count_tre(s, [t, r, e]) do 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