The Wayback Machine - https://web.archive.org/web/20251229031339/https://github.com/TheAlgorithms/Python/pull/3155
Skip to content

Conversation

@kowaltek
Copy link

Created problem_38 in project_euler

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@kowaltek kowaltek requested a review from dhruvmanila as a code owner October 10, 2020 14:41
Comment on lines 37 to 44
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
Copy link
Member

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
''

Suggested change
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'

Copy link
Author

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.

Comment on lines 48 to 49
for num in range(9487, 9233, -1):
num_to_check = int(str(num * 1) + str(num * 2))
Copy link
Member

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.

Copy link
Author

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').

Copy link
Member

@dhruvmanila dhruvmanila left a 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.

@kowaltek kowaltek requested a review from Kush1101 October 17, 2020 17:59
@dhruvmanila
Copy link
Member

Thank you for your contribution but currently, we are not accepting solution to problems that exist in this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

HTTPS · web.archive.org
← Home