Example #1
0
##Take the number 192 and multiply it by each of 1, 2, and 3:
##
##    192 1 = 192
##    192 2 = 384
##    192 3 = 576
##
##By concatenating each product we get the 1 to 9 pandigital, 192384576.
##We will call 192384576 the concatenated product of 192 and (1,2,3)
##
##The same can be achieved by starting with 9 and multiplying by
##1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the
##concatenated product of 9 and (1,2,3,4,5).
##
##What is the largest 1 to 9 pandigital 9-digit number that can be formed
##as the concatenated product of an integer with (1,2, ... , n) where n > 1

max = 987654321
t = []
from tools import is_pandigital_1to9

for i in range(1,100000):
    n = 1
    p = ""
    while len(p)<9:
        p = p + str(n*i)
        n = n+1
    if is_pandigital_1to9(p):
        t.append(p)
print t[len(t)-1]
Example #2
0
# The Fibonacci sequence is defined by the recurrence relation:
#
# Fn = Fn1 + Fn2, where F1 = 1 and F2 = 1.
# It turns out that F541, which contains 113 digits, is the first
# Fibonacci number for which the last nine digits are 1-9 pandigital
# (contain all the digits 1 to 9, but not necessarily in order).
# And F2749, which contains 575 digits, is the first Fibonacci
# number for which the first nine digits are 1-9 pandigital.
#
# Given that Fk is the first Fibonacci number for which the first
# nine digits AND the last nine digits are 1-9 pandigital, find k.

from tools import is_pandigital_1to9

f1 = 1
f2 = 1
k = 2
loop = True
while loop:
    temp = f1
    f1 += f2
    f2 = temp
    k += 1
    if is_pandigital_1to9(str(f1)[0: 9]):
        if is_pandigital_1to9(str(f1)[-9:]):
            print k
            loop = False