ProjectEuler


So a big part of all this Project Euler nonsense includes prime numbers. Problem 10, begs the ever-so-common question Find the sum of all the primes below one million. Obviously, the first attempt would be to just straight out calculate it using my previous program in Problem 3. Adapting that program to one million integers resulted in about 768 seconds (read: over 10 minutes) of time. Obviously this breaks the 1 minute rule the program needed to be tweaked.

Trying other various methods I still came up short with the result being about 176 seconds at best. To optimize my program I was mainly looking for some information on how prime numbers might be related to bits/bytes to see if I could perhaps try some bitwise operations to speed things up. In doing so, I came across an article suggesting that having an array of bits (essentially a long char) with each char representing a number in an array from 0 to x; x being the limit. Once this array was created, simply just iterate from 0 to the square root of your limit, and mark all multiples of any primes found on your way. Makes sense - and this greatly cuts down on all the harsh prime calculating going on in the background.
(more...)

So as many already probably know Euler was a famous European mathematician and physicist. Recently at work a lot of talk has been going around about Project Euler; basically a website which poses mathematical problems that need to be solved by writing program. So a few of us at work have decided to take the plunge and learn a completely new language while attempting to answer some of these questions.

So I guess I should start with saying I'll be using/learning Python for all of my problems. Not a terribly hard choice as I'm already pretty familiar with Perl and PHP which seem to be somewhat similar to Python. Anyways, if anyone else wants to get in on the fun. Feel free to do so and post links to your own blogs/solutions or simply just put them here! I plan on using these solutions as an excuse to actually get posting more on here. So, we'll see how that goes. I may also have to make some sort of hiding script so solutions aren't completely revealed to those that want to accomplish everything on their own. Without further adieu - the first 3 problems and my solutions. (more...)