Sudal's Garage

Project Euler 38 본문

Programming/Project Euler - python

Project Euler 38

_Sudal 2019. 3. 31. 05:00

Question: 


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?


문제:


192에 1,2,3을 각각 곱해보면 다음과 같다.

192 × 1 = 192
192 × 2 = 384
192 × 3 = 576

각각의 곱을 이어보면 192384576이 되는데 이 수는 1부터 9까지 한 번씩 사용한 팬디지털 수이다. 이 192384576을 192에 (1,2,3)을 곱한 팬디지털 곱이라 부르자.

9에 1,2,3,4,5를 각각 곱하여 그 곱들을 이어보면 918273645이 되고, 이는 9에 (1,2,3,4,5)를 곱한 팬디지털 곱이다.

n > 1 인 n에 대하여 (1,2, ..., n)를 곱한 아홉자리 팬디지털 곱 중 가장 큰 수는?


Solution:


def isPendi(n): # 회문임을 판별.
    if len(''.join(n)) == 9:
        if len(list(set(''.join(n)))) == 9:
            if not '0' in str(n):
                return True
    return False

num = 0
i = 1

while i < 10000:
    subject = list()
    n = 1
    while len(subject) < 9:
        subject += list(str(i*n))
        n += 1
    if isPendi(subject):
        if num < int(''.join(subject)):
            num = int(''.join(subject))
    i += 1



'Programming > Project Euler - python' 카테고리의 다른 글

Project Euler 40  (0) 2019.04.02
Project Euler 39  (0) 2019.04.01
Project Euler 37  (0) 2019.03.30
Project Euler 36  (0) 2019.03.29
Project Euler 35  (0) 2019.03.28