my solution to exercise 1-3