-
-
Notifications
You must be signed in to change notification settings - Fork 49.8k
Created problem_38 in project_euler #3155
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
Conversation
project_euler/problem_38/sol1.py
Outdated
| num = str(num) | ||
| for digit in range(1, 10): | ||
| digit = str(digit) | ||
| if digit in num: | ||
| num = num.replace(digit, "", 1) | ||
| else: | ||
| return False | ||
| return True if len(num) == 0 else False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can achieve the same by doing
''
| num = str(num) | |
| for digit in range(1, 10): | |
| digit = str(digit) | |
| if digit in num: | |
| num = num.replace(digit, "", 1) | |
| else: | |
| return False | |
| return True if len(num) == 0 else False | |
| return ''.join(sorted(str(num))) == '123456789' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's very concise. Thank you for pointing that out.
| for num in range(9487, 9233, -1): | ||
| num_to_check = int(str(num * 1) + str(num * 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you decide upon the range of numbers 9487, 9233?
Please elaborate more upon this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The range is exactly 9234 to 9487. Firts digit has to be nine to accomplish nine at the beginning of the num_to_check. The number has to have four digits to accomplish nine digit result. We can't use digit '1' as it would mean two '1's in our result, hence 9234. We also can't use anything greater than '4' as second digit, as that would mean two 9's in possible solution ('19' in the beginning of second product instead of '18').
dhruvmanila
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Announcement:
@mateuszkowalke
This message is sent to all pull requests which are OPEN, NOT MERGED, not containing 'wontfix' label and contains 'Project Euler' or 'Project' or 'Euler' (case doesn't matter) in their title. If this message doesn't apply to your pull request, please ignore this.
Message:
This is to notify all the users submitting a pull request for the Project Euler solution that the README.md file has been updated with all the style requirements necessary for the directory and solution files. Please read through it and make all the necessary changes required to your submission.
|
Thank you for your contribution but currently, we are not accepting solution to problems that exist in this repository. |


Created problem_38 in project_euler
Checklist:
Fixes: #{$ISSUE_NO}.