Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- X =[1,7,3,4,5,9]
- C = (1),(7,3),(4,5,9)
- # This algorithim belongs to Hope1995x on Reddit.
- if len(X) % 3 > 0:
- print('no')
- quit()
- using_this_for_second_loop=[];
- what_if_there_is_no_repeating_elements = 0
- # The first part of trying to solve the X3C problem
- # is to loop through each indidvual index of C.
- # I will then use a nested loop so that I can loop
- # thorugh indexes as if they were lists.
- # Indexes that contain elements that don't exist in X
- # will not be appended to the new list.
- # Indexes with repeating elements
- # will not be appended to the new list.
- for j in range(0, len(C)):
- convert_index_into_list = str(C[j])
- new_list = (re.sub("[^0-9,]", "", convert_index_into_list))
- new_list = new_list.split(',')
- new_list = list(map(int, new_list))
- make_sure_all_elements_exist_in_X = all(elem in new_list for elem in X)
- if make_sure_all_elements_exist_in_X:
- for jj in range(0, len(new_list)):
- if new_list.count(new_list[jj]) < 2:
- if jj == len(new_list) - 1:
- using_this_for_second_loop.append(c[j])
- what_if_there_is_no_repeating_elements = 1
- if what_if_there_is_no_repeating_elements == 0:
- using_this_for_second_loop = C
- # I will then modify the list that will be used for the 2nd loop.
- # This is to prevent semantic bugs.
- # Here the only elements that do exist are the one's THAT DON'T REPEAT
- # AND THE ONE'S THAT EXIST IN X.
- preparing_the_answer = str(using_this_for_second_loop)
- new_list_two = (re.sub("[^0-9,]", "", preparing_the_answer))
- new_list_thr = new_list_two.split(',')
- new_list_thr = list(map(int, new_list_thr))
- making_sure_all_elements_in_X = all(elem in new_list_thr for elem in X)
- if making_sure_all_elements_in_X:
- print('yes')
- else:
- print('no')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement