HTML & JS
def print_combinations(m, N):
    used = [False] * (m * N)
    subsets_holder = [[0] * N for _ in range(m)]
    print_combinations_recur(m, N, 0, used, subsets_holder, 0, N)


# Given numbers from 0 inclusive to m*N exclusive, print all combinations
# of m subsets of size N using the unused numbers starting from `start_number`
# that include N-sized subsets subsets_holder[0:cur_subset] and partial
# subset subsets_holder[cur_subset] which has the first `N-to_Fill` numbers filled.
def print_combinations_recur(m, N, start_number, used, subsets_holder, cur_subset, to_fill):
    if to_fill == N:
        if cur_subset == m:
            # Replace this printing if you want to do something else
            # with the combination stored in `subsetsHolder`.
            print(subsets_holder)
            return
        for i in range(m * N):
            if not used[i]:
                used[i] = True
                subsets_holder[cur_subset][0] = i
                print_combinations_recur(m, N, i + 1, used, subsets_holder, cur_subset, N - 1)
                used[i] = False
                break
    else:
        if to_fill == 0:
            print_combinations_recur(m, N, start_number, used, subsets_holder, cur_subset + 1, N)
        else:
            for i in range(start_number, m * N):
                if not used[i]:
                    subsets_holder[cur_subset][N - to_fill] = i
                    used[i] = True
                    print_combinations_recur(m, N, i + 1, used, subsets_holder, cur_subset, to_fill - 1)
                    used[i] = False


def batch_test():
    for m in range(1, 3):
        for N in range(1, 4):
            print("Combinations of ", m, " subsets of size ", N, ":")
            print_combinations(m, N)
            print()
    # print_combinations(4, 2);
    # print_combinations(2, 4);


if __name__ == "__main__":
    batch_test()

Generated URL:

Output:

Combinations of  1  subsets of size  1 :
[[0]]

Combinations of  1  subsets of size  2 :
[[0, 1]]

Combinations of  1  subsets of size  3 :
[[0, 1, 2]]

Combinations of  2  subsets of size  1 :
[[0], [1]]

Combinations of  2  subsets of size  2 :
[[0, 1], [2, 3]]
[[0, 2], [1, 3]]
[[0, 3], [1, 2]]

Combinations of  2  subsets of size  3 :
[[0, 1, 2], [3, 4, 5]]
[[0, 1, 3], [2, 4, 5]]
[[0, 1, 4], [2, 3, 5]]
[[0, 1, 5], [2, 3, 4]]
[[0, 2, 3], [1, 4, 5]]
[[0, 2, 4], [1, 3, 5]]
[[0, 2, 5], [1, 3, 4]]
[[0, 3, 4], [1, 2, 5]]
[[0, 3, 5], [1, 2, 4]]
[[0, 4, 5], [1, 2, 3]]

Report Bug