mirror of
https://github.com/jlengrand/project_euler.git
synced 2026-03-10 08:41:20 +00:00
Solves Problem 39. 1 minute time is reached, but the solution comes up
to be very ugly. I'm sure I can find something better than that ! Still have to perform some good work on prime numbers! (one day . . . ) I begin to lack some primes problems cause of that :s Signed-off-by: Julien Lengrand-Lambert <julien@lengrand.fr>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#My solutions to Project Euler 's website
|
||||
#My solutions to Project Euler 's website
|
||||
|
||||
[Project Euler](http://projecteuler.net/) is a website containing lots of problems aiming at being solved.
|
||||
I play around with them in order to sharpen my algorithm skills.
|
||||
@@ -44,6 +44,7 @@ Should be used in order to help future reuse of code :)
|
||||
30 - Find the sum of all the numbers that can be written as the sum of fifth powers of their digits. - < 3 sec <br />
|
||||
34 - Find the sum of all numbers which are equal to the sum of the factorial of their digits. - 30 sec <br />
|
||||
36 - Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2. - 0.933 <br />
|
||||
39 - If p is the perimeter of a right angle triangle, {a, b, c}, which value, for p <= 1000, has the most solutions? - 1min<br />
|
||||
42 - Using words.txt, a 16K text file containing nearly two-thousand common English words, how many are triangle words? - < 1 sec <br />
|
||||
45 - Find the next triangle number that is also pentagonal and hexagonal. - < 1 sec <br />
|
||||
48 - Find the last ten digits of 1^1 + 2^2 + ... + 1000^1000. - 0.053 <br />
|
||||
@@ -53,8 +54,9 @@ Should be used in order to help future reuse of code :)
|
||||
**In progress: **
|
||||
|
||||
26 - Find the value of d < 1000 for which 1/d contains the longest recurring cycle. <br />
|
||||
31 - Investigating combinations of English currency denominations. <br />
|
||||
35 - How many circular primes are there below one million? <br />
|
||||
39 - If p is the perimeter of a right angle triangle, {a, b, c}, which value, for p <= 1000, has the most solutions? <br />
|
||||
53 - How many values of C(n,r), for 1 <= n <= 100, exceed one-million? <br />
|
||||
|
||||
**WARNING : Spoil inside for those who want to solve problems by themselves :)**
|
||||
|
||||
|
||||
23
e_31.py
Normal file
23
e_31.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python
|
||||
'''
|
||||
Created on 10 feb. 2012
|
||||
|
||||
@author: Julien Lengrand-Lambert
|
||||
|
||||
DESCRIPTION: Solves problem 31 of Project Euler
|
||||
In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:
|
||||
|
||||
1p, 2p, 5p, 10p, 20p, 50p, L1 (100p) and L2 (200p).
|
||||
It is possible to make L2 in the following way:
|
||||
|
||||
1 * L1 + 1 * 50p + 2 * 20p + 1 * 5p + 1 * 2p + 3 * 1p
|
||||
How many different ways can L2 be made using any number of coins?
|
||||
'''
|
||||
def aaa():
|
||||
"""
|
||||
Returns
|
||||
"""
|
||||
return 1
|
||||
|
||||
if __name__ == '__main__':
|
||||
print "Answer : %d " % (1)
|
||||
49
e_39.py
49
e_39.py
@@ -11,14 +11,53 @@ If p is the perimeter of a right angle triangle with integral length sides, {a,b
|
||||
|
||||
For which value of p 1000, is the number of solutions maximised?
|
||||
'''
|
||||
def sum_power():
|
||||
def per_tri(max_per):
|
||||
"""
|
||||
Finds
|
||||
Returns the maximum number of solutions maximised for a given max value of perimeter.
|
||||
"""
|
||||
max_sol = 0
|
||||
max_p = 0
|
||||
for p in range(3, max_per + 1):
|
||||
print "%d/%d" %(p, max_per + 1)
|
||||
nb_sol = 0
|
||||
sols = []
|
||||
for a in range(1, p):
|
||||
for b in range(1, p - a):
|
||||
c = p - a - b
|
||||
if is_rect(a, b, c):
|
||||
if is_present([a, b, c], sols):
|
||||
pass
|
||||
else:
|
||||
sols.append([a, b, c])
|
||||
nb_sol += 1
|
||||
|
||||
if nb_sol > max_sol:
|
||||
max_sol = nb_sol
|
||||
max_p = p
|
||||
|
||||
return 1
|
||||
return max_p
|
||||
|
||||
def is_present(cur_sol, sols):
|
||||
"""
|
||||
Returns True if solution is already in the list
|
||||
"""
|
||||
for sol in sols:
|
||||
val = 0
|
||||
for side in cur_sol:
|
||||
if side in sol:
|
||||
val += 1
|
||||
|
||||
if val == len(cur_sol):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def is_rect(a, b, c):
|
||||
"""
|
||||
Returns true if the triangle is rectangle, c being the hypothenuse.
|
||||
"""
|
||||
return (a**2 + b**2 == c**2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# The major problem in there is to find the upper limit.
|
||||
print "Answer : %d " % (sum_power())
|
||||
# really ugly solution!
|
||||
print "Answer : %d " % (per_tri(1000))
|
||||
|
||||
28
e_53.py
Normal file
28
e_53.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
'''
|
||||
Created on 10 feb. 2012
|
||||
|
||||
@author: Julien Lengrand-Lambert
|
||||
|
||||
DESCRIPTION: Solves problem 53 of Project Euler
|
||||
There are exactly ten ways of selecting three from five, 12345:
|
||||
|
||||
123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
|
||||
|
||||
In combinatorics, we use the notation, 5C3 = 10.
|
||||
|
||||
In general,
|
||||
|
||||
nCr = n! / r!(nr)! ,where r n, n! = n(n1)...321, and 0! = 1.
|
||||
It is not until n = 23, that a value exceeds one-million: 23C10 = 1144066.
|
||||
|
||||
How many, not necessarily distinct, values of nCr, for 1 n 100, are greater than one-million?
|
||||
'''
|
||||
def aaa():
|
||||
"""
|
||||
Returns
|
||||
"""
|
||||
return 1
|
||||
|
||||
if __name__ == '__main__':
|
||||
print "Answer : %d " % (1)
|
||||
Reference in New Issue
Block a user