my solution of problem 1 :)