Skip to content

Instantly share code, notes, and snippets.

@im-noob
Created December 20, 2020 21:17
Show Gist options
  • Save im-noob/a0111f434e7f4bd1fd613dadb5655ce5 to your computer and use it in GitHub Desktop.
Save im-noob/a0111f434e7f4bd1fd613dadb5655ce5 to your computer and use it in GitHub Desktop.
Find Binary Tree or Possible Combination with different range
def generate_sequence(stop_arr):
arr_for_combination = []
arr = []
max_iteration = 1
for one_stop in stop_arr:
arr.append(0)
max_iteration *= one_stop + 1
max_iteration_copy = max_iteration
max_iteration = int(max_iteration / len(arr) + 1)
for i in range(max_iteration):
for j in arr:
# print(arr)
arr_for_combination.append(','.join([str(k) for k in arr]))
arr[0] += 1
for index, one_stop in enumerate(stop_arr):
if index == len(stop_arr) - 1:
break
if arr[index] > one_stop:
arr[index + 1] += 1
arr[index] = 0
final_arr = []
for one_combination in arr_for_combination:
temp_final = []
separate_one_combination = one_combination.split(',')
for one_element in separate_one_combination:
temp_final.append(int(one_element))
final_arr.append(temp_final)
return final_arr[0:max_iteration_copy]
for i in generate_sequence([2, 2, 2, 3]):
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment