mirror of
https://github.com/jlengrand/project_euler.git
synced 2026-03-10 08:41:20 +00:00
Solves problem 33 of Project Euler.
Ugly but result comes in an instant, so . . .
This commit is contained in:
@@ -43,6 +43,7 @@ Should be used in order to help future reuse of code :)
|
||||
29 - How many distinct terms are in the sequence generated by ab for 2 a 100 and 2 b 100? - < 1 sec <br />
|
||||
30 - Find the sum of all the numbers that can be written as the sum of fifth powers of their digits. - < 3 sec <br />
|
||||
31 - Investigating combinations of English currency denominations. - < 1 sec <br />
|
||||
33 - Discover all the fractions with an unorthodox cancelling method. < 1 sec <br />
|
||||
34 - Find the sum of all numbers which are equal to the sum of the factorial of their digits. - 30 sec - 16 sec <br />
|
||||
35 - How many circular primes are there below one million? <br />
|
||||
36 - Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2. - 0.933 <br />
|
||||
@@ -60,7 +61,6 @@ 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 />
|
||||
33 - Discover all the fractions with an unorthodox cancelling method. <br />
|
||||
43 - Find the sum of all pandigital numbers with an unusual sub-string divisibility property. <br />
|
||||
46 - What is the smallest odd composite that cannot be written as the sum of a prime and twice a square? <br />
|
||||
47 - Find the first four consecutive integers to have four distinct primes factors. <br />
|
||||
|
||||
36
e_33.py
36
e_33.py
@@ -11,7 +11,39 @@ There are exactly four non-trivial examples of this type of fraction, less than
|
||||
|
||||
If the product of these four fractions is given in its lowest common terms, find the value of the denominator.
|
||||
'''
|
||||
def simplify(num, den):
|
||||
"""
|
||||
Tries to simplify the fraction in a dumb way, returns null otherwise
|
||||
TODO : Write in a nicer way
|
||||
"""
|
||||
if str(num)[0] == str(den)[0]:
|
||||
return (int(str(num)[1]),int(str(den)[1]))
|
||||
elif str(num)[1] == str(den)[0]:
|
||||
return (int(str(num)[0]),int(str(den)[1]))
|
||||
elif str(num)[0] == str(den)[1]:
|
||||
return (int(str(num)[1]),int(str(den)[0]))
|
||||
elif str(num)[1] == str(den)[1]:
|
||||
return (int(str(num)[0]),int(str(den)[0]))
|
||||
else:
|
||||
return None
|
||||
|
||||
def non_trivial_simpl():
|
||||
"""
|
||||
Searches for all fractions that can be simplified in a curious way
|
||||
"""
|
||||
# We want to have fractions less than one
|
||||
fin_nums = 1
|
||||
fin_dens = 1
|
||||
for den in range(11, 100):
|
||||
for num in range(10, den):
|
||||
if '0' not in str(den): # avoiding trivial examples
|
||||
res = simplify(num, den)
|
||||
if res != None:
|
||||
if ((res[1] != 0) and(float(num)/den == float(res[0])/res[1]) ):
|
||||
fin_nums *= res[0]
|
||||
fin_dens *= res[1]
|
||||
|
||||
return fin_dens / fin_nums # I do this because I know I can
|
||||
|
||||
if __name__ == '__main__':
|
||||
print 1
|
||||
#print "Answer : %d " % (last_ten())
|
||||
print "Answer : %d " % (last_ten())
|
||||
9
e_47.py
9
e_47.py
@@ -14,10 +14,17 @@ The first three consecutive numbers to have three distinct prime factors are:
|
||||
|
||||
644 = 2^2 7 * 23
|
||||
645 = 3 * 5 * 43
|
||||
646 = 2 17 * 19.
|
||||
646 = 2 * 17 * 19.
|
||||
|
||||
Find the first four consecutive integers to have four distinct primes factors. What is the first of these numbers?
|
||||
'''
|
||||
import pickle
|
||||
|
||||
def consecutive_primes(num):
|
||||
"""
|
||||
Returns the first of the firs num consecutive primes.
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print 1
|
||||
|
||||
Reference in New Issue
Block a user