Solution to problem 6
Partial solution to problem 7