Moved problems till e045.py to Python 2.

This commit is contained in:
2019-07-16 21:17:21 -04:00
parent ddb61ff731
commit 301033d17d
20 changed files with 324 additions and 0 deletions

36
python/e038.py Normal file
View File

@@ -0,0 +1,36 @@
def is_concatenated_product_9_pandigital(n):
validation_array = [0 for _ in range(9)]
result = ""
total_length = 0
for i in range(1, 10):
current_product = str(i * n)
for d in current_product:
if d == "0":
return False
index = ord(d) - 49
validation_array[index] += 1
if validation_array[index] > 1:
return False
total_length += len(current_product)
result += current_product
if total_length == 9:
return result
if total_length > 9:
return False
raise Exception("We should not get here.")
def euler_038():
r = []
for i in range(10000):
p = is_concatenated_product_9_pandigital(i)
if p:
r.append(int(p))
return max(r)
if __name__ == "__main__":
print("e038.py: " + str(euler_038()))
assert(euler_038() == 932718654)