Created
September 15, 2016 17:14
-
-
Save devpruthvi/6edba7a693efbde47dfb87476c3dc54c 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
sets = [ [0], #see this dummy set it is important, this is set_0 | |
#because initially we add -arr[0] or arr[0] to 0 | |
[10,-10], | |
[30,-10,10,-30], | |
[100,20,40,-40,60,-20,-80,0,-60,-100], | |
[60,0,20,-40,-20,-60]] | |
# my array is 1 based so ignore the zero | |
arr = [0,10,20,40,30] | |
list_A = [] | |
list_B = [] | |
current_element = 0 | |
current_set = 4 # Total number of sets in this case is n=4 | |
while current_set >= 1: | |
print("here") | |
for element in sets[current_set-1]: | |
if element + arr[current_set] == current_element: | |
list_B.append(arr[current_set]) | |
current_element = element | |
current_set -= 1 | |
break | |
elif element - arr[current_set] == current_element: | |
list_A.append(arr[current_set]) | |
current_element = element | |
current_set -= 1 | |
break | |
print(list_A,list_B) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment