Working solution to 4
Added faster version of problem 4