-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Conversation
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.
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.
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.
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.
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.
Looks like a good start! Let's focus on these small changes and then we will take a look at the algorithm itself.
project_euler/problem_092/sol1.py
Outdated
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 | ||
|
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.
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.
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 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.
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.
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.
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.
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.
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.
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 ?
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.
Maybe you can copy the list first, mutate and finally append to the result for this function? @sharmapulkit04
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.
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.
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.
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.
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. |
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! |
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.