solution for prob 22 finished