problem 43, albeit rather slow