This takes advantage of the fact that every third Fibonacci number is even in order to avoid having to check for each number f it is even.
a=1
b=1
c=2
x=0
while c < 4000000:
x=x+c
a=b+c
b=a+c
c=a+b
print x
If you found this little bit of code helpful, then please consider donating so that I can continue coding.
You can donate here
Showing posts with label project euler. Show all posts
Showing posts with label project euler. Show all posts
Thursday, 11 September 2008
Tuesday, 2 September 2008
First Project Euler problem solved!
Well, the first problem was easy enough, at least after I managed to get my for loop working.
This is the python script I ended up with:
If you found this little bit of code helpful, then please consider donating so that I can continue coding.
You can donate here
This is the python script I ended up with:
x=0
for i in range(1, 1000):
if i % 3 == 0 or i % 5 == 0:
x=x+i
print xIf you found this little bit of code helpful, then please consider donating so that I can continue coding.
You can donate here
Project Euler problems
I though it might be nice to have some understanding of another programming language. After thinking about it for a little while, I decided on Python. So now I had the problem of trying to learn it. After a bit of searching, I came across Project Euler, which has a set of maths problems to solve by writing programs to solve them. It seems like a great way to get into programming.
I've just downloaded Python, so we'll see how long it takes to get that installed and to write the solution for the first problem.
If you have found this post helpful, then please consider donating, so that I can continue blogging.
You can donate here.
I've just downloaded Python, so we'll see how long it takes to get that installed and to write the solution for the first problem.
If you have found this post helpful, then please consider donating, so that I can continue blogging.
You can donate here.
Subscribe to:
Posts (Atom)