solved problem 9 in python and probably php but it's too slow to tell