code for task 3-1 from erlang book