Exemplo n.º 1
0
def combine_primes_below(r, N, primes):
    pos = range(r)
    L = len(primes) 
    solutions = []
    if r > L:
        return solutions
    
    while True:    
        ps = [primes[j] for j in pos]
        prod = product_of(ps)
        if prod <= N:
            solutions.append(ps)
        
        index = -1
        for i in range(0, r):
            if pos[r-1-i] == L-1-i:
                prod = product_of(ps[:r-1-i])
                continue
            elif prod > N:
                prod = product_of(ps[:r-1-i])
                continue
            else:
                index = r-1-i
                break
        if index == -1:
            break
        pos[index] += 1
        for i in range(index+1, r):
            pos[i] = pos[i-1] + 1
    
    return solutions
Exemplo n.º 2
0
def solve(number, size_of_subset):
    largest_product = 0
    for subset in consecutive_subsets_of(str(number), size_of_subset):
        product = product_of([int(i) for i in subset])
        if product > largest_product:
            largest_product = product
    return largest_product 
Exemplo n.º 3
0
def prime_powers_below(primes_base, N):
    # TODO code has to be fixed, is just an estimate for ceiling N
    prod = product_of(primes_base)
    prime_powers_base = [powers_below(p, (N*p)/prod) for p in primes_base]
    for factorization in product(prime_powers_base):
        if product_of_factorization(factorization) <= N:
            yield factorization
Exemplo n.º 4
0
def solve(N):
    primes = find_product_primes_below(N)
    factors_set = [[n for n in powers_below(p, N, 1)] for p in primes]

    max_frac = 0.0
    max_number = 0
    for factors in produce(factors_set):
        n = product_of(factors)
        if n > N:
            continue
        phi = product_of([num - num/p for (num,p) in zip(factors, primes)])

        frac = float(n)/phi
        if frac > max_frac:
            print(n, frac, factors)
            max_frac = frac
            max_number = n
    return max_number
Exemplo n.º 5
0
def solve(ceiling):
    factors = []
    for p in primes_until(ceiling):
        factor = p**max_power_of_x_below_y(p, ceiling)
        factors.append(factor)
    return product_of(factors)
Exemplo n.º 6
0
def get_max_product_in_lines(lines, nums):
    max_product = 0
    for subset in consecutive_subsets_of(lines, nums):
        p = product_of(subset)
        max_product = max(p, max_product)
    return max_product
Exemplo n.º 7
0
"""
An irrational decimal fraction is created by concatenating the positive integers:
0.123456789101112131415161718192021...
It can be seen that the 12th digit of the fractional part is 1.

If d_(n) represents the n-th digit of the fractional part, find the value of the following expression:
d_(1) x d_(10) x d_(100) x d_(1000) x d_(10000) x d_(100000) x d_(1000000)
"""
from projecteuler import product_of

if __name__ == '__main__':
    limit = 10**6
    fraction = ""
    for i in range(1, limit):
        fraction += str(i)
        if(len(fraction) > limit):
            break
        
    indexes = [10**i for i in range(7)]    
    result = product_of([int(fraction[i-1]) for i in indexes])
        
    print("The value of the expression in problem 40 is %(result)d" % vars())
        
    
Exemplo n.º 8
0
def product_of_factorization(pps):
    return product_of([x**exp for (x,exp) in pps])