Skip to content

problem solution for eulers problem_038(Pandigital multiples) #3452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
34 changes: 34 additions & 0 deletions project_euler/problem_038/sol2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
problem_038: https://projecteuler.net/problem=38
Problem statement: What is the largest 1 to 9 pandigital 9-digit
number that can be formed as the concatenated
product of an integer with (1,2, ... , n) where n > 1
"""


def solution():
# largest pandigital number
largest = 0
# for loop to loop till 4 digits
for i in range(1, 10000):
# value for concatenated string
mul = ""
int_eger = 1
# if the multiplication < 9 digits
while len(mul) < 9:
# concatenating the product at each stage
mul += str(i * int_eger)
int_eger += 1
# check for digits less than 9
# check for all 1-9 numbers
# check if '0' not in concatenated string
if (len(mul) == 9) and (len(set(mul)) == 9) and ("0" not in mul):
# check if multiplication is greater than largest
if int(mul) > largest:
largest = int(mul)
# return the largest
return largest


if __name__ == "__main__":
print(solution())