About this page
This is where I put my solutions (or work towards solutions) to Project Euler problems. The problems are something I do in my spare time, so this will not be frequently updated.
I tend to use python for solving these problems, because it's just so quick to write.
Prime numbers
For many of these problems it's useful to have a list of prime numbers. The primes below are listed are here.
The code for finding these primes is:
flags = []
limit = 1000000
for i in range(0,limit):
flags.append(i>1)
for i in range(2,limit):
if flags[i]==True:
j = i
while j<limit:
j = j+i
if j<limit:
flags[j] = False
for i in range(2,limit):
if flags[i]:
print i
To read the primes into a list:
primes_file = open('../primes/primes.txt')
primes = []
for p in primes_file.read().split('\n'):
primes.append(int(p))
Stopwatch
Just for fun I time how long my solutions take. I place the following snippets before and after the main code:
import time time_0 = time.time() ... time_1 = time.time() print 'That took %.0fms'%(1000*(time_1-time_0))