solve problem five by brute force