Copied problem 7, slight modifications
pushing a few more