solved exercise 2 from sw2