Guest User

Untitled

a guest
Jan 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. def check_palindrome(s):
  2. """Checks whether the given string is palindrome"""
  3.  
  4. if s == s[::-1]:
  5. return True
  6.  
  7. product_pal = []
  8. for i in range (999,900,-1):
  9. for j in range (999,900,-1):
  10. product = i * j
  11. if check_palindrome(str(product)):
  12. product_pal.append(product)
  13. print"i =" , i , "j = ",j, "for", product
  14. print max(product_pal)
  15.  
  16. def check_palindrome(s):
  17. """Checks whether the given string is palindrome"""
  18. return s == s[::-1]
  19.  
  20. max_product = 0
  21. for i in range(999, 900, -1):
  22. for j in range(i, 900, -1):
  23. product = i * j
  24. if check_palindrome(str(product)):
  25. max_product = max(max_product, product)
  26. print "i =", i, "j = ", j, "for", product
  27. print max_product
  28.  
  29. def get_max_three_digit_product():
  30. max_product = 0
  31. for i in range(999, 900, -1):
  32. for j in range(i, 900, -1):
  33. product = i * j
  34. if check_palindrome(str(product)):
  35. max_product = max(max_product, product)
  36. return max_product
  37.  
  38. if __name__ == "__main__":
  39. print get_max_three_digit_product()
  40.  
  41. for i in range(999,99,-1):
  42. for j in range(999,i-1,-1):
  43. # check palindrome
  44.  
  45. def is_palindrome(n):
  46. s = str(n)
  47. return s == s[::-1]
  48.  
  49. def get_biggest_palindrome():
  50. max_product = 0
  51. for i in xrange(999, 99, -1):
  52. if max_product >= 999*i:
  53. # no need to iterate further down
  54. break
  55. for j in xrange(999, i-1, -1):
  56. p = j * i
  57. if max_product >= p:
  58. # no need to iterate further down
  59. break
  60. if is_palindrome(p):
  61. max_product = p
  62. return max_product
Add Comment
Please, Sign In to add comment