And yet another solution
Simple solution to problem 2