## Posts Tagged ‘Project Euler’

### Project Euler Challenge #3 : Finding Primes

Thursday, July 24th, 2014

Finally, it gets interesting. Below is my third attempt on this problem, the first taking so long to complete that I improved it before its first iteration, and the second just wasn’t good enough.

```def find_primes(number):
"""Returns a set of primes"""
primes = set()
if number != int(number):
raise Exception('Must be int') # Improve this
if number < 4:
return primes
i = 2
while number > 1:
while number % i == 0:
number = number / i
i += 1
return primes
```

In this solution, I learned some basic uses for python’s set builtin. I’m a better person today.

### Project Euler Challenge #2 : Fibonacci Sums

Thursday, July 24th, 2014

Another straightforward challenge: find the sum of all even numbers in the Fibonacci sequence less than four million.

``` def even_fib_sum(limit = 10):
num = 2
pre = 1
tot = 2
while num < limit:
num += pre
pre = num - pre
if num % 2 == 0:
tot += num
```

Yeah, yawn.

### Project Euler Challenge #1 : Threes and Fives

Thursday, July 24th, 2014

So I’ve been trying to improve my coding technique while thinking about some fun math problems, and Project EulerÂ will help me achieve exactly that. It’s unfortunate that they were hacked recent, so a lot of their functionality has been removed, but it will still confirm your answer.

My rules for these challenges:

```def euler1(n=1000):