Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- X =[2,1,3,5,9,0]
- C = (2,1,3),(5),(9,0)
- # This algorithim belongs to Hope1995x on Reddit.
- if len(X) % 3 > 0:
- print('no')
- quit()
- # This will check for no's
- convert_to_string = str(C)
- new_list = (re.sub("[^0-9,]", "", convert_to_string))
- new_list_one = new_list.split(',')
- new_list_one = list(map(int, new_list_one))
- if len(new_list_one) < len(X):
- 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.
- # I used a function from https://thispointer.com/python-3-ways-to-check-if-there-are-duplicates-in-a-list/
- def checkIfDuplicates_3(listOfElems):
- 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 X for elem in new_list)
- print(new_list)
- if make_sure_all_elements_exist_in_X:
- for elem in new_list:
- if listOfElems.count(elem) < 2:
- 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 X for elem in new_list_thr)
- if making_sure_all_elements_in_X:
- print('yes')
- else:
- print('no')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement