Sudal's Garage

Project Euler 40 본문

Programming/Project Euler - python

Project Euler 40

_Sudal 2019. 4. 2. 05:00

Question: 


An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021...

It can be seen that the 12th digit of the fractional part is 1.

If dn represents the nth digit of the fractional part, find the value of the following expression.

d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000



문제:


양의 정수를 순서대로 이어붙여서 다음과 같은 무리수를 만들 수 있다.

0.123456789101112131415161718192021...

위 수의 소수점 12번째 자리 숫자는 1이다.

dn이 위 수의 소수점 n번째 자리 숫자라고 할 때, 다음을 구하여라.

d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000


Solution:


import time
digits = [0]
i = 1
start = time.time()
while len(digits) < 1000001:
    for x in range(len(str(i))):
        digits.append(int(list(str(i))[x]))
    i += 1

result = digits[1] * digits[10] * digits[100] * digits[1000] * digits[10000] * digits[100000] * digits[1000000]
print("result = {0}\nFound in ...{1:.3f}s".format(result,time.time() - start))


설명할 게 없는 무난한 코드


0.8초 걸렸다.




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

Project Euler 42  (0) 2019.04.04
Project Euler 41  (0) 2019.04.03
Project Euler 39  (0) 2019.04.01
Project Euler 38  (0) 2019.03.31
Project Euler 37  (0) 2019.03.30