defmodule Main do def main do IO.read(:line) |> String.trim() |> solve |> IO.puts() end def solve(n) do n |> String.to_charlist() |> Enum.reverse() |> each_slice_3 |> Enum.map(fn x -> x |> Enum.reverse() |> Enum.concat(',') end) |> Enum.reverse() |> Enum.join() |> String.slice(0..-2) end def each_slice_3(list) do each_slice_3_rec(list, []) end def each_slice_3_rec(list, result) do case list do [a, b, c | d] -> each_slice_3_rec(d, result |> Enum.concat([[a, b, c]])) [] -> result l -> result |> Enum.concat([l]) end end end