We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The comments so far don't really indicate the best approach to this problem.
Doing a brute-force under a limit is very inefficient. You might be able to pass all test cases this way by tweaking with the upper limit, but that's only because the constrants on this problem are far too low. The constraints should be closer to 3 <= N <= 11.
Rather than doing a brute-force, it's best to turn this into a permutations problem. There are 10 digits, 0-9. So we want to find permutations of 0^N - 9^N that have a sum that meets the criteria.
Project Euler #30: Digit Nth powers
You are viewing a single comment's thread. Return to all comments →
The comments so far don't really indicate the best approach to this problem.
Doing a brute-force under a limit is very inefficient. You might be able to pass all test cases this way by tweaking with the upper limit, but that's only because the constrants on this problem are far too low. The constraints should be closer to 3 <= N <= 11.
Rather than doing a brute-force, it's best to turn this into a permutations problem. There are 10 digits, 0-9. So we want to find permutations of 0^N - 9^N that have a sum that meets the criteria.