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.
It's true, some people spend too much time overoptimizing something that doesn't matter in a particular application. In this case, with the constraint 1<=n<=1000, a simple brute force, especially when you stop at n/2, works very well.
However, if I'm programming something that I know is to be used in a more general fashion, the performance implications here are huge. The code above dramatically reduces the time needed, as the brute force method is very inefficient (particularly for a large n).
Day 19: Interfaces
You are viewing a single comment's thread. Return to all comments →
It's true, some people spend too much time overoptimizing something that doesn't matter in a particular application. In this case, with the constraint 1<=n<=1000, a simple brute force, especially when you stop at n/2, works very well.
However, if I'm programming something that I know is to be used in a more general fashion, the performance implications here are huge. The code above dramatically reduces the time needed, as the brute force method is very inefficient (particularly for a large n).