solved problem 7, although solution is slow