Skip to content

Add combinations #1015

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

Merged
merged 5 commits into from
Jul 14, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding doctest
  • Loading branch information
obelisk0114 committed Jul 14, 2019
commit a175ca342d4a7dcb559ac28db2679f4ec897e303
19 changes: 15 additions & 4 deletions backtracking/all_combinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@


def generate_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
"""

result = []
Copy link
Member

Choose a reason for hiding this comment

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

Please insert this function docstring here:

def generate_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
    """

create_all_state(1, n, k, [], result)
return result
Expand All @@ -29,7 +39,8 @@ def print_all_state(total_list):
print(*i)


n = 4
k = 2
total_list = generate_all_combinations(n, k)
print_all_state(total_list)
if __name__ == '__main__':
n = 4
k = 2
total_list = generate_all_combinations(n, k)
print_all_state(total_list)