summaryrefslogtreecommitdiff
path: root/038.py
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2014-08-31 20:21:45 +0200
committerReiner Herrmann <reiner@reiner-h.de>2014-08-31 20:35:09 +0200
commit95341b61b030c9e1290f3b326cb7ec584f543aea (patch)
tree852386fa04d32eb859bca11c0eff7b5ef9e50f00 /038.py
parent571164d977f91925c4c76a292f74f5f93d09ae23 (diff)
moved files to higher directory after split to new repositoryHEADtrunk
Diffstat (limited to '038.py')
-rw-r--r--038.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/038.py b/038.py
new file mode 100644
index 0000000..bc43644
--- /dev/null
+++ b/038.py
@@ -0,0 +1,43 @@
+
+def is_pandigital(x):
+ digits = 10*[0]
+
+ while x > 0:
+ digit = x % 10
+ if digit == 0:
+ return False
+ digits[digit] += 1
+ x /= 10
+
+ for i in range(1, 10):
+ if digits[i] != 1:
+ return False
+
+ return True
+
+
+def pandigital(x):
+ result = str(x * 1)
+ count = 1
+
+ while len(result) < 9:
+ count += 1
+ result += str(x * count)
+
+ if len(result) > 9:
+ return 0
+
+ if is_pandigital(int(result)):
+ return int(result)
+
+ return 0
+
+max_pd = 0
+for i in xrange(9876):
+ p = pandigital(i)
+ if p > max_pd:
+ max_pd = p
+ i += 1
+
+print max_pd
+