mirror of
https://github.com/jlengrand/project_euler.git
synced 2026-03-10 08:41:20 +00:00
Updates README to include running time.
Work on primes to be performed. dump has been created to avoid recalculation each time. But I 'll spend some time working on sieves. Signed-off-by: Julien Lengrand-Lambert <julien@lengrand.fr>
This commit is contained in:
@@ -13,35 +13,35 @@ The script are named as e_problemnumber_inc. The higher the inc, the finer my so
|
||||
Here is a list of all already solved problems, with a one line explanation.
|
||||
Should be used in order to help future reuse of code :)
|
||||
|
||||
1 - Add all the natural numbers below one thousand that are multiples of 3 or 5.
|
||||
2 - By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
|
||||
3 - Find the largest prime factor of a composite number.
|
||||
4 - Find the largest palindrome made from the product of two 3-digit numbers.
|
||||
5 - What is the smallest number divisible by each of the numbers 1 to 20?
|
||||
6 - What is the difference between the sum of the squares and the square of the sums?
|
||||
7 - Find the 10001st prime.
|
||||
8 - Discover the largest product of five consecutive digits in the 1000-digit number.
|
||||
9 - Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000. (a^2 + b^2 = c^2)
|
||||
10 - Calculate the sum of all the primes below two million.
|
||||
11 - What is the greatest product of four adjacent numbers on the same straight line in the 20 by 20 grid?
|
||||
12 - What is the value of the first triangle number to have over five hundred divisors?
|
||||
13 - Find the first ten digits of the sum of one-hundred 50-digit numbers.
|
||||
14 - Find the longest sequence using a starting number under one million.
|
||||
15 - Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?
|
||||
16 - What is the sum of the digits of the number 2^1000?
|
||||
17 - How many letters would be needed to write all the numbers in words from 1 to 1000?
|
||||
18 - Find the maximum sum travelling from the top of the triangle to the base.
|
||||
19 - How many Sundays fell on the first of the month during the twentieth century?
|
||||
20 - Find the sum of digits in 100!
|
||||
21 - Evaluate the sum of all amicable pairs under 10000. (d(a) = b, d(b) = a)
|
||||
22 - What is the total of all the name scores in the file of first names?
|
||||
23 - Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.
|
||||
24 - What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
|
||||
25 - What is the first term in the Fibonacci sequence to contain 1000 digits?
|
||||
27 - Find a quadratic formula that produces the maximum number of primes for consecutive values of n.
|
||||
36 - Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2.
|
||||
48 - Find the last ten digits of 1^1 + 2^2 + ... + 1000^1000.
|
||||
67 - Using an efficient algorithm find the maximal sum in the triangle?
|
||||
1 - Add all the natural numbers below one thousand that are multiples of 3 or 5. - 0.011
|
||||
2 - By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. - 0.011
|
||||
3 - Find the largest prime factor of a composite number. - too long -
|
||||
4 - Find the largest palindrome made from the product of two 3-digit numbers. - 0.790
|
||||
5 - What is the smallest number divisible by each of the numbers 1 to 20? - 4.102
|
||||
6 - What is the difference between the sum of the squares and the square of the sums? - 0.013
|
||||
7 - Find the 10001st prime. - too long -
|
||||
8 - Discover the largest product of five consecutive digits in the 1000-digit number. - 0.045
|
||||
9 - Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000. (a^2 + b^2 = c^2) - 1.500
|
||||
10 - Calculate the sum of all the primes below two million. - too long
|
||||
11 - What is the greatest product of four adjacent numbers on the same straight line in the 20 by 20 grid? - 0.048
|
||||
12 - What is the value of the first triangle number to have over five hundred divisors? - too long
|
||||
13 - Find the first ten digits of the sum of one-hundred 50-digit numbers. - 0.012
|
||||
14 - Find the longest sequence using a starting number under one million. - too long
|
||||
15 - Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner? - 0.012
|
||||
16 - What is the sum of the digits of the number 2^1000? - 0.012
|
||||
17 - How many letters would be needed to write all the numbers in words from 1 to 1000? - 0.012
|
||||
18 - Find the maximum sum travelling from the top of the triangle to the base. - 0.012
|
||||
19 - How many Sundays fell on the first of the month during the twentieth century? - 0.088
|
||||
20 - Find the sum of digits in 100! - 0.031
|
||||
21 - Evaluate the sum of all amicable pairs under 10000. (d(a) = b, d(b) = a) - 9.100
|
||||
22 - What is the total of all the name scores in the file of first names? - 0.082
|
||||
23 - Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. - too long
|
||||
24 - What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? - too long
|
||||
25 - What is the first term in the Fibonacci sequence to contain 1000 digits? - 0.741
|
||||
27 - Find a quadratic formula that produces the maximum number of primes for consecutive values of n. - too long
|
||||
36 - Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2. - 0.933
|
||||
48 - Find the last ten digits of 1^1 + 2^2 + ... + 1000^1000. - 0.053
|
||||
67 - Using an efficient algorithm find the maximal sum in the triangle? - 0.027
|
||||
|
||||
**In progress: **
|
||||
|
||||
|
||||
1
e_19.py
1
e_19.py
@@ -159,4 +159,3 @@ if __name__ == '__main__' :
|
||||
start_date = Date(1901, 1, 1)
|
||||
end_date = Date(2000, 12, 31)
|
||||
print "Answer is : %d" %(days_in_period("sunday", 1, start_date, end_date))
|
||||
raw_input() # USed to keep Windows terminal open
|
||||
|
||||
4
e_24.py
4
e_24.py
@@ -34,6 +34,4 @@ def all_permutations(seq):
|
||||
return temp
|
||||
|
||||
if __name__ == '__main__' :
|
||||
lexi_perm("012", 1)
|
||||
#print "Answer is : %d" %(lexi_perm("0123456789", 1000000))
|
||||
raw_input() # USed to keep Windows terminal open
|
||||
print "Answer is : %d" %(lexi_perm("0123456789", 1000000))
|
||||
|
||||
1
e_36.py
1
e_36.py
@@ -41,4 +41,3 @@ def sum_palindroms(max):
|
||||
|
||||
if __name__ == '__main__' :
|
||||
print "Answer is : %d" % (sum_palindroms(1000000))
|
||||
raw_input()
|
||||
78500
primes_list.dup
Normal file
78500
primes_list.dup
Normal file
File diff suppressed because it is too large
Load Diff
50
primes_list.py
Normal file
50
primes_list.py
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
##---
|
||||
# Julien Lengrand-Lambert
|
||||
#Created on : Thu Jan 19 10:12:06 CET 2012
|
||||
#
|
||||
# DESCRIPTION : Puts the list of all primes below one million in a file.
|
||||
Seeing the number of problems using primes, this could be useful
|
||||
##---
|
||||
"""
|
||||
import pickle
|
||||
|
||||
def is_prime(value):
|
||||
"""
|
||||
Returns True or False depending whether value is prime or not.
|
||||
"""
|
||||
start = 2
|
||||
while (start <= value / 2):
|
||||
if value % start == 0 :
|
||||
return False
|
||||
else :
|
||||
start += 1
|
||||
return True
|
||||
|
||||
def prime_list(max_val):
|
||||
"""
|
||||
Returns a list of all primes below max_val
|
||||
"""
|
||||
plist = []
|
||||
cur = 2
|
||||
while (cur < max_val):
|
||||
if (cur % 1000) == 0:
|
||||
print "%d/%d" % (cur, max_val)
|
||||
|
||||
if (is_prime(cur)):
|
||||
plist.append(cur)
|
||||
cur += 1
|
||||
|
||||
return plist
|
||||
|
||||
if __name__ == '__main__' :
|
||||
if 0: # creating file
|
||||
plist = prime_list(1000000)
|
||||
# dumping into primes_list.dump
|
||||
pickle.dump(plist, open("primes_list.dup", "wb"))
|
||||
else: # reading and using file
|
||||
plist = pickle.load(open("primes_list.dup", "rb"))
|
||||
print plist[0:100]
|
||||
raw_input()
|
||||
print "Done!"
|
||||
Reference in New Issue
Block a user