Project Euler - 4

회문 구하기

두 개의 3자리 숫자의 곱으로 만들어지는 가장 큰 회문을 구하라.
"""
Largest palindrome product

A palindromic number reads the same both ways.
The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

Find the largest palindrome made from the product of two 3-digit numbers.
"""


def is_palindrome(n):
s = str(n)
s2 = str()
i = len(s) - 1
while i >= 0:
s2 += s[i]
i -= 1
return s == s2


if __name__ == '__main__':
maxi = 0
for a in range(100, 1000):
for b in range(100, 1000):
num = a * b
if is_palindrome(num):
print(num)
if num > maxi:
maxi = num
print("max = ", maxi)
회문 여부를 판별하기 위한 함수를 정의하였다. 함수가 입력 받은 숫자를 문자열로 변환 후 순서를 뒤집는다.

댓글

  1. titanium glasses for sale | TITanium Art
    Find the perfect titanium titanium easy flux 125 amp welder glasses for sale by titanium fat bike TITanium Art on TITanium titanium element Art mens wedding bands titanium | Shop sunscreen with zinc oxide and titanium dioxide top fashion brands & designs.

    답글삭제

댓글 쓰기

이 블로그의 인기 게시물

Project Euler - 3

메인 스크립트

예외 처리