Project Euler - Problem 4


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/usr/bin/python
  2.  
  3. print "\nProject Euler - Problem 4"
  4. print "This program finds the largest"
  5. print "palindrome made from the product"
  6. print "of two 3-digit numbers.\n"
  7.  
  8. import array
  9.  
  10. facta = 999
  11. factb = 999
  12. test = 1
  13. ans = 0
  14. maximum = 0
  15. while facta > 99:
  16. while factb > 99:
  17. num = facta * factb
  18. ans = str(num) + '$'
  19. x = array.array('c', ans[0:-1]).tolist()
  20. y = array.array('c', ans[0:-1]).tolist()
  21. x.reverse()
  22. if (y == x):
  23. if (maximum < num):
  24. maximum = num
  25. factb = factb - 1
  26. facta = facta - 1
  27. factb = 999
  28.  
  29. print 'result = %s' % maximum

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.