Ian Lewis avatar Ian Lewis committed 2a9ed1d

Added solution for problem 4 (Python)

Comments (0)

Files changed (1)

+"""
+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.
+"""
+
+X = 3
+
+def euler4(x):
+    start = 10 ** (x-1)
+    end = (10 ** x) - 1
+
+    max_palindrome = 0
+    for left in xrange(start, end):
+        # Don't try numbers already used on
+        # the left
+        for right in xrange(left, end):
+            y = left * right
+            stry = str(y)
+            if stry == stry[::-1] and y > max_palindrome:
+                max_palindrome = y
+    return max_palindrome
+
+if __name__ == '__main__':
+    print euler4(X)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.