According to Project Euler I’m 1% genius. That means I’m probably smarter than you are. One thing I have noticed though is that code for Project Euler is generally way to complicated. Is it any worse than anyone else’s? I wouldn’t say so really. Once compiled into an executable I bet my code isn’t any slower to solve the problem than anyone else running brute force methods like I have thus far but I have thus far made my code extremely modular and I’ve used a lot of arrays. I tend to be the only one using C++ (from the few I’ve looked at) that uses arrays in solving these problems.

C++ Question: Is there a downside to arrays or are people just scared of them?

Enjoy the Penguins!

3 Comments

    • Mike Lundy
    • Posted 9 November 2007 at 7:15 PM
    • Permalink

    If you’re using static arrays, they have their uses if you’re trying to avoid runtime memory allocation, but in most cases you’re better off using a vector. It integrates better with the rest of the stl functions, and you can use a vector like an array (including memcpy(&myvec[0]…) and the like- if you do, note that &myvec != &myvec[0]).

    If you’re using dynamic arrays (new blah[32]) you should definitely be using an stl container. Having to use delete[] instead of delete is annoying and one more thing to remember (and screw up), and it has the same problem that every raw pointer type has- if an exception is thrown, you /have/ to catch it right there, or your array will leak. To solve that latter problem, you can use a smart_ptr from boost. shared_ptr is awesome, especially since you can stick it into stl containers.

    So, yeah, think twice before you use an array, but don’t feel as though you can never use them. Hopefully that’s helpful :)

    • Bryan Østergaard
    • Posted 10 November 2007 at 9:51 AM
    • Permalink

    After about 1.5 hour with Project Euler I’m now 6% genius. Does that make me a lot smarter than you?

    I’ve only solved the first 10 assigments but they have all been incredibly easy imo. I’m hoping they get a lot harder later on.

  1. Bryan,

    It doesn’t make your smarter. Only more bored.


One Trackback/Pingback

  1. [...] recently read a post from Steven Oliver mentioning his experience with Project Euler, which seems to be a collection of math and [...]