def test():
    a = fibo(541)
    a = str(a)
    print is_pandigital(a[-9:])
    print a[-9:]
    b = fibo(2749)
    b = str(b)
    print is_pandigital(b[:9])
    print b[:10]
def main1():
    """very slow"""
    cnt = 329300
    while True:
        fib = fibo(cnt)
        if is_pandigital(str(fib)[-9:]) and is_pandigital(str(fib)[:9]):
            break
        else:
            print cnt
            cnt += 1
    print cnt
def gen_pandigitals(digit):
    """This function is very slow. expecially digit is over 5.
    If digit is 9, this function return Memmory Error."""
    pandigitals = []
    below = 10 ** (digit-1)
    above = 10 * below
    for i in range(below, above):
        if is_pandigital(i, s=digit):
            pandigitals.append(i)
    return pandigitals
示例#4
0
def main():
    start = default_timer()

    max_ = 0

    #   A brute force approach is used, starting with 1 and multiplying
    #   the number by 1, 2 etc., concatenating the results, checking if
    #   it's 1 to 9 pandigital, and going to the next number when the
    #   concatenated result is greater than the greatest 9 digit pandigital
    #   value. The limit is set to 10000, since 1*10000=10000, 2*10000=20000 and
    #   concatenating this two numbers a 10-digit number is obtained.
    for i in range(1, 10000):
        n = 0
        j = 1

        while True:
            tmp = i * j
            n = n + tmp
            j = j + 1

            if n > max_ and is_pandigital(n, 9):
                max_ = n
            if i * j < 10:
                n = n * 10
            elif i * j < 100:
                n = n * 100
            elif i * j < 1000:
                n = n * 1000
            elif i * j < 10000:
                n = n * 10000
            elif i * j < 100000:
                n = n * 100000

            if n > 987654321:
                break

    end = default_timer()

    print('Project Euler, Problem 38')
    print('Answer: {}'.format(max_))

    print('Elapsed time: {:.9f} seconds'.format(end - start))
示例#5
0
def main():
    start = default_timer()

    #   8- and 9-digit pandigital numbers can't be prime, because
    #   1+2+...+8=36, which is divisible by 3, and 36+9=45 which is
    #   also divisible by 3, and therefore the whole number is divisible
    #   by 3. So we can start from the largest 7-digit pandigital number,
    #   until we find a prime.
    i = 7654321

    while (i > 0):
        if is_pandigital(i, len(str(i))) and is_prime(i):
            break


#       Skipping the even numbers.
        i = i - 2

    end = default_timer()

    print('Project Euler, Problem 41')
    print('Answer: {}'.format(i))

    print('Elapsed time: {:.9f} seconds'.format(end - start))
def main():
    for n in xrange(9876, 9123, -1):
        p = str(n*1) + str(n*2)
        if is_pandigital(p):
            print p
            break
示例#7
0
# http://blog.dreamshire.com/project-euler-104-solution/
from projecteuler import is_pandigital


def top_digits(n):
    t = n * 0.20898764024997873 + (-0.3494850021680094)
    t = int((pow(10, t - int(t) + 8)))
    return t


fk, f0, f1 = 2, 1, 1
while not is_pandigital(f1) or not is_pandigital(top_digits(fk)):
    f0, f1 = f1, (f1 + f0) % 10 ** 9
    fk += 1
print "Project Euler 104 Solution =", fk
示例#8
0
def main():
    start = default_timer()

    n = 0
#   Initially I used a bigger array, but printing the resulting products
#   shows that 10 values are sufficient.
    products = zeros(10, int)

#   To get a 1 to 9 pandigital concatenation of the two factors and product,
#   we need to multiply a 1 digit number times a 4 digit numbers (the biggest
#   one digit number 9 times the biggest 3 digit number 999 multiplied give
#   8991 and the total digit count is 8, which is not enough), or a 2 digit 
#   number times a 3 digit number (the smallest two different 3 digits number,
#   100 and 101, multiplied give 10100, and the total digit count is 11, which
#   is too many). The outer loop starts at 2 because 1 times any number gives
#   the same number, so its digit will be repeated and the result can't be 
#   pandigital. The nested loop starts from 1234 because it's the smallest 
#   4-digit number with no repeated digits, and it ends at 4987 because it's
#   the biggest number without repeated digits that multiplied by 2 gives a 
#   4 digit number.
    for i in range(2, 9):
        for j in range(1234, 4987):
            p = i * j
            num_s = str(i) + str(j) + str(p)

            if len(num_s) > 9:
                break

            num = int(num_s)

            if is_pandigital(num, 9):
                products[n] = p
                n = n + 1

#   The outer loop starts at 12 because 10 has a 0 and 11 has two 1s, so
#   the result can't be pandigital. The nested loop starts at 123 because
#   it's the smallest 3-digit number with no digit repetitions and ends at
#   833, because 834*12 has 5 digits.
    for i in range(12, 99):
        for j in range(123, 834):
            p = i * j

            num_s = str(i) + str(j) + str(p)

            if len(num_s) > 9:
                break

            num = int(num_s)

            if is_pandigital(num, 9):
                products[n] = p
                n = n + 1

#   Sort the found products to easily see if there are duplicates.
    products = np.sort(products[:n])

    sum_ = products[0]

    for i in range(1, n):
        if products[i] != products[i-1]:
            sum_ = sum_ + products[i]

    end = default_timer()

    print('Project Euler, Problem 32')
    print('Answer: {}'.format(sum_))

    print('Elapsed time: {:.9f} seconds'.format(end - start))
示例#9
0
#http://blog.dreamshire.com/project-euler-104-solution/
from projecteuler import is_pandigital

def top_digits(n):
     t = n * 0.20898764024997873 + (-0.3494850021680094)
     t = int((pow(10, t - int(t) + 8)))
     return t

fk, f0, f1 = 2, 1, 1
while not is_pandigital(f1) or not is_pandigital(top_digits(fk)):
    f0, f1 = f1, (f1+f0) % 10**9
    fk += 1
print "Project Euler 104 Solution =", fk
def main2():
    fn, f0, f1 = 2, 1, 1
    while not is_pandigital(f1) or not is_pandigital(top_digits(fn)):
        f0, f1 = f1, (f1 + f0) % 10 ** 9
        fn += 1
    print fn