ProjectEuler

I first became familiar with Leonhard Euler in a Differential Equations class at UT Dallas.  In this context, it was all about Euler’s method for solving differential equations like  :

ax²y″+bxy′+cy = 0; around x=0

This project has less to do with calculus, and more to do with the site projecteuler.net.  Euler was a prolific mathematician and can be attributed to a number of important methods and identities in applied mathematics, physics, fluid dynamics, and even music.

Wiki Stuff

History

In the past the Project Euler series of problems has been helpful in getting started with a new language.  I’ve used it to pick up the basics in flow control and algorithm building in VB, VBScript, C++, and now Python.  Each time, I create a new login and work through the problems a first time with a focus on getting the answer, then run another pass focusing on optimizing those solutions once I am more familiar with the syntax and best practices of a language.

My Python experience has been a little unique when compared to other languages, partly due to my new experience in Linux web hosting and the command-line focused nature of the work.  I built out a simple control and timing structure to allow easy implementation of new solutions.

From my ProjectEuler repo :

This solution is pretty basic, but allows the easy addition of problem solutions as functions named  problem_n  where  n  is the problem number.

Another approach could implement the same code as a function wrapper.

Problem Functions

The top of my project_euler.py file looks like this :

You see a summation of each problem, followed by a problem solution.  In the refinement process I plan on using sub-versions to denote improved functions (ie  problem_1a ).

Thus far, I’ve only needed the math python module for calculations, and  time for basic operation timing.  The intention of this exercise is to write my own solutions while minimally leveraging available shortcuts.  Some of the functions section (more to come on that later) functions I’ve written have already been useful in a few more serious projects.

Problem 1’s solution is provided – a basic list comprehension makes a tidy, one-line answer.  Each additional problem will follow the same pattern (though most won’t be one-line solutions).

Problem 2 is a little more complex, involving a separate functions section function  gen_fib()  to return a fibonacci sequence up to 4,000,000.  Stay tuned for more, including a breakdown of  some of the math functions going into these solutions.