def eul33(): """If the product of these four fractions is given in its lowest common terms, find the value of the denominator.""" fracs = [] for d in range(10, 100): for n in range(10, d): common = set(eul.get_digits(n)).intersection(eul.get_digits(d)) for digit in common: if digit: r_n = int(str(n).replace(str(digit), "", 1)) r_d = int(str(d).replace(str(digit), "", 1)) if r_d and r_n / r_d == n / d: fracs.append((n, d)) n = d = 1 for frac in fracs: n *= frac[0] d *= frac[1] return d / math.gcd(n, d)
def eul32(): """"Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.""" products = set() for product in range(1000, 10000): if len(set(eul.get_digits(product))) == len(str(product)): for i in eul.get_proper_divisors(product): j = int(product / i) test = ''.join([str(i), str(j), str(i*j)]) if len(test) == 9 and eul.pandigital(test): products.add(i*j) return sum(products)
def eul34(): """Find the sum of all numbers which are equal to the sum of the factorial of their digits.""" return sum([i for i in range(3, 100000) if sum([math.factorial(x) for x in eul.get_digits(i)]) == i])
def eul30(): """Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.""" return sum([x for x in range(2, 1000000) if sum([y ** 5 for y in eul.get_digits(x)]) == x])
def eul16(): """What is the sum of the digits of the number 2^n = 1000?""" return sum([x for x in eul.get_digits(2 ** 1000)])