Пример #1
0
def smallest_multiple(limit):
    product_ = Basic.product(range(1, limit + 1))
    primes = primes_under(limit)
    primes_product = Basic.product(primes)
    max_step = product_ // primes_product
    for multiplier in range(1, max_step + 1):
        num = primes_product * multiplier
        for j in range(2, limit + 1):
            if not is_factor_of(j, num):
                break
        else:
            return num
    return product_
Пример #2
0
def solve008(num, length):
    digits = [int(i) for i in list(num)]
    max_product = 1
    for i in range(len(num) - length + 1):
        product = Basic.product(digits[i:i + length])
        if product > max_product:
            max_product = product
    return max_product
Пример #3
0
def solve004(digit_size):
    check_size = digit_size // 10
    checks = range(digit_size - check_size, digit_size)
    mult_table = Basic.multiplication_table(checks, checks)
    palindromes = list()
    for row in mult_table:
        for num in row:
            if General.is_palindrome(num):
                palindromes.append(num)
    return max(palindromes)
Пример #4
0
def nth_permutation(n, list_):
    permutation = list()
    num_permutations = Basic.factorial(len(list_))
    n %= num_permutations
    while n > 0:
        permutations_per_index = num_permutations // len(list_)
        index = n // permutations_per_index
        n %= permutations_per_index
        num_permutations = permutations_per_index
        permutation.append(list_.pop(index))
    permutation += list_
    return permutation
Пример #5
0
def num_factors_of(num):
    primes = prime_factors_of(num)
    count_values = General.count_list(primes).values()
    return Basic.product([x + 1 for x in count_values])
Пример #6
0
def n_choose_k(n, k):
    n_fact = Basic.factorial(n)
    nk_fact = Basic.factorial(n - k)
    k_fact = Basic.factorial(k)
    return n_fact // (k_fact * nk_fact)
Пример #7
0
def solve006(size):
    square_of_sum = Basic.square_of_sum_up_to(size)
    sum_of_squares = Basic.sum_of_squares_up_to(size)
    return square_of_sum - sum_of_squares
Пример #8
0
def solve020(num):
    factorial = Basic.factorial(num)
    return General.sum_of_digits(factorial)
Пример #9
0
def solve012(limit):
    num = 2
    while NumberTheory.num_factors_of(Basic.sum_up_to(num)) <= limit:
        num += 1
    return Basic.sum_up_to(num)