aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-14 12:45:32 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-14 12:45:32 +0100
commit268681aa37ab8f048e6f595608578f1154fe2416 (patch)
tree0030616dcf30f1230ce794e313253563fb53e209 /python
parent2030aed15343b830f6a68e4746f42a921fa3d917 (diff)
downloadproject_euler-268681aa37ab8f048e6f595608578f1154fe2416.tar.gz
project_euler-268681aa37ab8f048e6f595608578f1154fe2416.tar.bz2
project_euler-268681aa37ab8f048e6f595608578f1154fe2416.zip
problem 38 in python
Diffstat (limited to 'python')
-rw-r--r--python/038-pandigital_multiples.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/python/038-pandigital_multiples.py b/python/038-pandigital_multiples.py
index be8fedc..33c7592 100644
--- a/python/038-pandigital_multiples.py
+++ b/python/038-pandigital_multiples.py
@@ -1,7 +1,7 @@
# ###
# Pandigital multiples
# Problem 38
-#
+#
# Take the number 192 and multiply it by each of 1, 2, and 3:
# 192 × 1 = 192
# 192 × 2 = 384
@@ -12,7 +12,26 @@
# ###
-def concatenated_prod(n):
- cprod = ""
-
+import itertools
+
+
+def is_palindrom(s):
+ return len(s) == 9 and ''.join(sorted(s)) == '123456789'
+
+
+largest = 0
+
+for n in range(1, 987654321):
+ results = []
+ for mul in itertools.count(1):
+ results.append(n * mul)
+ str_res = ''.join([str(x) for x in results])
+ res = int(str_res)
+ if is_palindrom(str_res) and res > largest:
+ largest = res
+ print(largest)
+ if res > 987654321:
+ break
+
+print(largest)