solution in erlang