반응형
앞에서부터 읽을 때나 뒤에서부터 읽을 때나 모양이 같은 수를 대칭수(palindrome)라고 부릅니다.
두 자리 수를 곱해 만들 수 있는 대칭수 중 가장 큰 수는 9009 (= 91 × 99) 입니다.
세 자리 수를 곱해 만들 수 있는 가장 큰 대칭수는 얼마입니까?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
palindrome = [] | |
def get_palindrome(num1, num2) : | |
max_palindrome = 0 | |
num2_org = num2 | |
while num1 > (num1/10) : | |
while num2 > (num2/10) : | |
multipled_num = num1*num2 | |
if is_palindrome(multipled_num) and (max_palindrome < multipled_num): | |
max_palindrome = multipled_num | |
num2 -= 1 | |
num1 -= 1 | |
num2 = num2_org | |
return max_palindrome | |
def is_palindrome(num) : | |
if str(num) == str(num)[::-1] : | |
return True | |
else : | |
return False | |
print(get_palindrome(9999, 9999)) |
반응형
'개발 > 알고리즘 문제' 카테고리의 다른 글
[Project Euler 06] 1부터 100까지 "제곱의 합"과 "합의 제곱"의 차는? (0) | 2016.03.01 |
---|---|
[Project Euler 05] 1 ~ 20 사이의 어떤 수로도 나누어 떨어지는 가장 작은 수 (0) | 2016.03.01 |
[Project Euler 03] 가장 큰 소인수 구하기 (0) | 2016.03.01 |
[Project Euler 02] 피보나치 수열에서 4백만 이하이면서 짝수인 항의 합 (0) | 2016.02.17 |
[Project Euler 01] 1000보다 작은 자연수 중에서 3 또는 5의 배수를 모두 더하면? (0) | 2016.02.17 |
댓글