Uh oh!
There was an error while loading. Please reload this page.
Add combinations - #1015
Conversation
cclauss
left a comment
There was a problem hiding this comment.
Adding this doctest would be a nice addition but I approve this PR in its current state.
| def generate_all_combinations(n: int, k: int) -> [[int]]: | ||
| result = [] |
There was a problem hiding this comment.
Please insert this function docstring here:
defgenerate_all_combinations(n: int, k: int) -> [[int]]:
""" >>> generate_all_combinations(n=4, k=2) 1 2 1 3 1 4 2 3 2 4 3 4 """| n = 4 | ||
| k = 2 | ||
| total_list = generate_all_combinations(n, k) | ||
| print_all_state(total_list) |
There was a problem hiding this comment.
Please put these four lines under a if __name__ == '__main__':
if__name__=='__main__':
n=4k=2total_list=generate_all_combinations(n, k)
print_all_state(total_list)Or just replace the four lines with:
if__name__=="__main__":
importdoctestdoctest.testmod()This should not change the functionality of your script but it should give it a new superpower:
- python3 -m doctest -v backtracking/all_combinations.py
cclauss
commented
Jul 14, 2019
It would be cool to think up more helpful variable names than n and k. |
cclauss
commented
Jul 14, 2019
Is this ready to be merged or are you still working on it? |
cclauss
commented
Jul 14, 2019
cclauss
commented
Jul 14, 2019
Is this ready to be merged or are you still working on it? |
obelisk0114
commented
Jul 14, 2019
It's ready to be merged. |
cclauss
commented
Jul 14, 2019
import itertools ; print(list(itertools.combinations(range(1, 5), 2))) |
* Update Bucket Sort time complexity analysis * Add combinations * Adding doctest * Fix doctest problem
Return all possible combinations of k numbers out of 1 ... n.