Created
June 23, 2021 19:36
-
-
Save grey-area/d94a881abe16319a9b44f18367737f5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_equal_partitions(L, r, left=0, k=0, partition=[], partition_list=[]): | |
if len(L) == 0: | |
return partition_list + [[tuple(partition[start:start+r]) for start in range(0, len(partition), r)]] | |
else: | |
if k == 0: | |
left = 0 | |
for idx, elem in enumerate(L[left:len(L) - (r - 1 - k)]): | |
remove_idx = left + idx | |
partition_list = find_equal_partitions(L[:remove_idx] + L[remove_idx + 1:], r, remove_idx, (k + 1) % r, partition + [elem], partition_list) | |
return partition_list | |
L = [1, 2, 3, 4, 5, 6] | |
ans = find_equal_partitions(L, r=3) | |
print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment