Adopted new convention from template

This commit is contained in:
David Doblas Jiménez 2022-09-30 21:07:53 +02:00
parent 6b55d7b25e
commit 48bd3200b0

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python
""" """
Created on 03 Jun 2021 Created on 03 Jun 2021
@ -17,25 +17,24 @@ def compute():
""" """
Take the number 192 and multiply it by each of 1, 2, and 3: Take the number 192 and multiply it by each of 1, 2, and 3:
192 × 1 = 192 192 x 1 = 192
192 × 2 = 384 192 x 2 = 384
192 × 3 = 576 192 x 3 = 576
By concatenating each product we get the 1 to 9 pandigital, By concatenating each product we get the 1 to 9 pandigital,
192384576. We will call 192384576 the concatenated product of 192384576. We will call 192384576 the concatenated product of
192 and (1,2,3) 192 and (1,2,3)
The same can be achieved by starting with 9 and multiplying by The same can be achieved by starting with 9 and multiplying by
1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is
the concatenated product of 9 and (1,2,3,4,5). the concatenated product of 9 and (1,2,3,4,5).
What is the largest 1 to 9 pandigital 9-digit number that can What is the largest 1 to 9 pandigital 9-digit number that can
be formed as the concatenated product of an integer with be formed as the concatenated product of an integer with
(1,2, ... , n) where n > 1? (1,2, ... , n) where n > 1?
""" """
results = [] ans = []
# Number must 4 digits (exactly) to be pandigital # Number must 4 digits (exactly) to be pandigital
# if n > 1 # if n > 1
for i in range(1, 10_000): for i in range(1, 10_000):
@ -43,14 +42,13 @@ def compute():
number = "" number = ""
while len(number) < 9: while len(number) < 9:
number += str(integer * i) number += str(integer * i)
if sorted(number) == list('123456789'): if sorted(number) == list("123456789"):
results.append(number) ans.append(number)
integer += 1 integer += 1
return max(results) return max(ans)
if __name__ == "__main__": if __name__ == "__main__":
print(f"Result for Problem 38 is {compute()}")
print(f"Result for Problem 38: {compute()}")