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

Added first solution to Project Euler problem 92 #4043

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 1 commit into from

Conversation

sharmapulkit04
Copy link
Contributor

Describe your change:

  • 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}.

@ghost ghost added awaiting reviews This PR is ready to be reviewed require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required labels Dec 19, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will only modify the labels accordingly.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@ghost ghost removed the require descriptive names This PR needs descriptive function and/or variable names label Dec 23, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will only modify the labels accordingly.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@ghost ghost removed the require tests Tests [doctest/unittest/pytest] are required label Dec 23, 2020
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.

Looks like a good start! Let's focus on these small changes and then we will take a look at the algorithm itself.

Comment on lines 80 to 88
Appends the list of all the possible ways in which an n digts can
be distributed among 9 digits at the end of a 2-d list all_distributions.
>>> all_possible_distributions([],[0]*10,5,0) is None
True
>>> all_possible_distributions([],[0]*10,8,0) is None
True

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a better description regarding what the function is doing.

Also, the doctests are redundant. In this function, you're mutating the parameter which is not a good practice. Instead, what you can do is to make a copy of the list and mutate that list and return it. This way you will be able to test this function appropriately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function appends the total no, of ways in which the number current can be distributed among the indices 0-9 of the list. i.e when we add all the contents of each_distribution it will lead to current. The each_distribution list is just a temporary list used to create a particular distribution.The all_distributions is a list of all possible current_distributions. The index starts from 0 and the function recursively increases the index by 1 and terminates when it reaches 9 and then appends the formed each_distribution list to all_distributions list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying the 2-d list at every recursive call will increase the complexity by a large factor. Though it will be able to solve the problem within the given constraints it will not be able to generalize for a large input taking a toll on the performance of the algorithm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the function can be modified to return a large 2-d list of all possible distributions but in that case reformatting the returned 2-d list to so that there would max 88 characters in each line cause doctest to fail.
ss

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying the 2-d list at every recursive call will increase the complexity by a large factor. Though it will be able to solve the problem within the given constraints it will not be able to generalize for a large input taking a toll on the performance of the algorithm.

The function uses brute force method to generate all possible combinations ,thus it would make the function very slow. Should I still consider doing it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can copy the list first, mutate and finally append to the result for this function? @sharmapulkit04

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unable to understand what you are saying @poyea . Are you suggesting to copy the 2-d list at start of function call? If that is the case then what I am trying to say is that the function uses recursion to calculate all possible configurations, so if I copy the entire 2-d list at every recursive call, it will increase the complexity by a large factor and will make the function very slow.

@ghost ghost added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Dec 24, 2020
@ghost ghost removed the awaiting changes A maintainer has requested changes to this PR label Dec 24, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will only modify the labels accordingly.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Dec 24, 2020
@stale
Copy link

stale bot commented Mar 5, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Used to mark an issue or pull request stale. label Mar 5, 2021
@stale
Copy link

stale bot commented Mar 20, 2021

Please reopen this pull request once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions!

@stale stale bot closed this Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed stale Used to mark an issue or pull request stale.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants