highest palindrome with 3 digit numbers in python

后端 未结 13 1231
梦如初夏
梦如初夏 2021-02-01 10:35

In problem 4 from http://projecteuler.net/ it says:

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-d

13条回答
  •  悲&欢浪女
    2021-02-01 11:13

    Simple:

    def is_pallindrome(n):
        s = str(n)
        for n in xrange(1, len(s)/2 + 1):
            if s[n-1] != s[-n]:
                return False    
        return True
    
    largest = 0
    for j in xrange(100, 1000):
        for k in xrange(j, 1000):
            if is_pallindrome(j*k):
                if (j*k) > largest: largest = j*k
    print largest
    

提交回复
热议问题