second solution to p39 and compare the two algorithms