Grifter

Largest palindrome with two three digit factors

Jun 4th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. #Import Libraries
  2. import numpy as np
  3.  
  4. #Declare initial empty arrays
  5. num = []
  6. palindromes = []
  7.  
  8. #Declare function which will reverse strings
  9. def reverse(r):
  10.     return int(str(r)[::-1])
  11.  
  12. #Generate array of numbers with two three digit factors
  13. for x in range(100,999):
  14.     for y in range(100,999):
  15.         num.append(x*y)
  16.  
  17. #Isolate palindromes
  18. for x in range(0,len(num)):
  19.     s = (str(num[x]))    
  20.     if (num[x]-(reverse(num[x])))==0:
  21.         palindromes.append(num[x])
  22.  
  23. #Use NumPy to reorder array in ascending order and print the final value in the array.
  24. print(np.sort(palindromes)[(len(palindromes)-1)])
Advertisement
Add Comment
Please, Sign In to add comment