コード例 #1
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
# What is the largest n-digit pandigital prime that exists?

from functions import allprimes
from functions import ispandigital

primes=allprimes(10000000)[::-1]

for n in primes:
    if(ispandigital(n)==1):
        print(n)
        break
コード例 #2
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# 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?

from functions import ispandigital

largest = 1
for p in range(1,10000):
    n=''
    q=1
    while(len(n)<9):
        n=n+''.join(str(p*q))
        q += 1
    if(len(n)==9 and ispandigital(int(n))==1):
        largest=max(largest,int(n))
print(largest)
コード例 #3
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.
# The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.
# Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
# HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.

from functions import ispandigital

carpimlar=[]
for a in range(1,500):
    for b in range(1,2000):
        q=''.join([str(a),str(b),str(a*b)])
        if(len(str(q))==9 and ispandigital(q)==1):
            carpimlar.append(a*b)
carpimlar.sort()

for n in carpimlar:
    while not (carpimlar.count(n)==1):
        carpimlar.remove(n)
print(sum(carpimlar))
コード例 #4
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# 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?

from functions import ispandigital

largest = 1
for p in range(1, 10000):
    n = ''
    q = 1
    while (len(n) < 9):
        n = n + ''.join(str(p * q))
        q += 1
    if (len(n) == 9 and ispandigital(int(n)) == 1):
        largest = max(largest, int(n))
print(largest)