Esempio n. 1
0
File: p07x.py Progetto: jpaeng/PE
def left_ordered_fraction(in_fraction, max_d):
    """Return the numerator and denominator of the reduced fraction immediately below in_fraction in an ordered list
    of fractions with d <= max_d.

    :param in_fraction: reference fraction in the form (numerator, denominator)
    :param max_d:       maximum denominator to check
    :return:            reduced proper fraction of the form (numerator, denominator)
    """

    in_fraction = (in_fraction[0]/in_fraction[1], (in_fraction[0], in_fraction[1]))
    min_delta = (in_fraction[0], (0, 0))

    # Loop through all denominators checking just the fraction to the left of in_fraction
    for d in range(2, max_d+1):
        n = int(d * in_fraction[0])
        fraction = n/d
        delta = in_fraction[0] - fraction
        if 0.0 < delta < min_delta[0]:
            min_delta = (delta, (n, d))

    return common.reduce_fraction(min_delta[1][0], min_delta[1][1])
Esempio n. 2
0
File: p03x.py Progetto: jpaeng/PE
     print(coin_combinations(200, [200, 100, 50, 20, 10, 5, 2, 1], 1))
     print(coin_combinations(1, [200, 100, 50, 20, 10, 5, 2, 1], 1))
 elif problem_num == 32:
     print(is_pandigital_3(39, 186, 39*186))
     print(pandigital_products())
     print(sum(pandigital_products()))
 elif problem_num == 33:
     print()
     zfraction_list = digit_canceling_fractions()
     num_product = 1
     den_product = 1
     for fraction in zfraction_list:
         num_product *= fraction[0]
         den_product *= fraction[1]
     print(zfraction_list)
     print(common.reduce_fraction(num_product, den_product))
 elif problem_num == 34:
     print()
     print(factorial_sum_list(200))
     print(factorial_sum_list())
 elif problem_num == 35:
     print(circular_primes(100))
     print(len(circular_primes(1000000)))
 elif problem_num == 36:
     print(double_base_palindromes(1000))
     print(double_base_palindromes(1000000))
 elif problem_num == 37:
     prime_list_10M = common.sieve_erathosthenes(10000000)
     print(next_right_extend_prime('379', prime_list_10M))
     print(next_left_extend_prime('797', prime_list_10M))
     print(truncatable_primes())