some algorithms in erlang