Esempio n. 1
0
def run(limit):
    step = 1
    num = 1
    denom = 2
    count = 0
    for _ in range(limit):
        if int_log10(denom + num) > int_log10(denom):
            count += 1
        num, denom = denom, ( denom * denom + step ) // num
        step *= -1
    print(count)
Esempio n. 2
0
def run():
    idx = 0
    for fib in fibonacci2():
        idx += 1
        if is_pandigital(fib % 1000000000):
            first9 = fib
            digits = int_log10(first9) + 1
            first9 //= 10**(digits - 9)
            print(idx, first9)
            if is_pandigital(first9):
                return idx
Esempio n. 3
0
def run2(n: int):
    '''only works for powers of 10'''
    count = 0
    s89 = get_test_set(n)
    digits = [d for d in range(1, 10)]
    num_digits = int_log10(n-1) + 1
    for d in range(1, num_digits+1):
        for comb in combinations_with_replacement(digits, d):
            sq_sum = sum([n*n for n in comb])
            if sq_sum in s89:
                possibilites = c(num_digits, d) * len({x for x in permutations(comb)})
                count += possibilites
    return count
Esempio n. 4
0
def run3(n: int):
    '''only works for powers of 10'''
    count = 0
    s89 = get_test_set(n)
    digits = [d for d in range(1, 10)]
    num_digits = int_log10(n-1) + 1
    for d in range(1, num_digits+1):
        for comb in combinations_with_replacement(digits, d):
            sq_sum = sum([n*n for n in comb])
            if sq_sum in s89:
                p = c(num_digits, d)
                #  * len({x for x in permutations(comb)})

                cc = [factorial(v) for k, v in Counter(comb).items()]
                f = factorial(d)
                for i in cc:
                    f //= i
                possibilites = p * f
                count += possibilites
    return count
Esempio n. 5
0
def long_div(num, denom, prec):
    res = 0
    carry = digit(num, 0)
    dig = int_log10(num // denom)
    if dig > 0:
        prec += dig
    digits = 0
    count = False
    i = 1
    while True:
        res *= 10
        quot = carry // denom
        res += quot
        subtr = quot * denom
        carry = (carry - subtr) * 10 + digit(num, i)
        i += 1
        if quot: count = True
        if count: digits += 1
        if digits > prec: break
    return res
Esempio n. 6
0
def digit(num, d):
    shift = int_log10(num) - d + 1
    if shift > 0:
        return num % 10**shift // 10**(shift - 1)
    else:
        return 0