Project Euler: math and programming

By 1772, Leonhard Euler had proved that 2,147,...

Image via Wikipedia

“The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context.”

I was pointed to project euler by a friend at work this week; And I am intrigued. This is a site that has a list of mathematical problems that could be attacked by hand and mind but as they progress this would become a bit of a problem and so programming would be the better way to handle it.

I think it’s cool, a nice way to give yourself some programming practice and expand your math skills at the same time. It’s easy and fun and you should do it in either a language you are just learning or a new one (Might I suggest Python or Lua.)

The first puzzle is easy and fun, “Add all the natural numbers below one thousand that are multiples of 3 or 5.” I did it in Python and it’s not that hard. there are a number of ways to do it, the hardest I think would be sum the totals of all of the 3’s from 0 to 999, all of the 5’s from 0 to 995 and delete the totals of all the 15’s from 0 to 995 (because they were counted twice in the first two.)  OR you could just loop from 0 to 999 and add any numbers that are divisible evenly by 3 or 5.

Now you could copy other peoples code, or google the answers but what fun or use would that be? So in the spirit of you will learn from this and not copy me I offer an example.

def main():
    print "Problem 1"
    print "Find the sum of all the multiples of 3 or 5 below 1000."
    total = 0
    for x in range(1000):
            print x
            total += x
            print x
            total +=x
    print total

Have fun, go and play a little. Pop back in and tell us what you think.


About echlinm

Computer Programmer/Systems Analyst/Hacker S31
This entry was posted in Computers and Internet, Fun, hackers, Open Source, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s