 # x3c-solver

a guest
Apr 8th, 2020
2,574
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import re
2.
3. X =[2,1,3,5,9,0]
4. C = (2,1,3),(5),(9,0)
5.
6. # This algorithim belongs to Hope1995x on Reddit.
7.
8.
9. if len(X) % 3 > 0:
10.   print('no')
11.   quit()
12.
13. # This will check for no's
14.
15. convert_to_string = str(C)
16. new_list = (re.sub("[^0-9,]", "", convert_to_string))
17. new_list_one = new_list.split(',')
18. new_list_one = list(map(int, new_list_one))
19.
20. if len(new_list_one) < len(X):
21.  print('no')
22.  quit()
23.
24. using_this_for_second_loop=[];
25. what_if_there_is_no_repeating_elements = 0
26.
27. # The first part of trying to solve the X3C problem
28. # is to loop through each indidvual index of C.
29.
30. # I will then use a nested loop so that I can loop
31. # thorugh indexes as if they were lists.
32.
33. # Indexes that contain elements that don't exist in X
34. # will not be appended to the new list.
35.
36. # Indexes with repeating elements
37. # will not be appended to the new list.
38.
39.
40. # I used a function from https://thispointer.com/python-3-ways-to-check-if-there-are-duplicates-in-a-list/
41.
42.
43.
44. def checkIfDuplicates_3(listOfElems):
45.     for j in range(0, len(C)):
46.         convert_index_into_list = str(C[j])
47.         new_list = (re.sub("[^0-9,]", "", convert_index_into_list))
48.         new_list = new_list.split(',')
49.         new_list = list(map(int, new_list))
50.         make_sure_all_elements_exist_in_X = all(elem in X for elem in new_list)
51.         print(new_list)
52.         if make_sure_all_elements_exist_in_X:
53.             for elem in new_list:
54.                 if listOfElems.count(elem) < 2:
55.                     using_this_for_second_loop.append(C[j])
56.                     what_if_there_is_no_repeating_elements = 1
57.
58. if what_if_there_is_no_repeating_elements == 0:
59.     using_this_for_second_loop = C
60.
61.
62. # I will then modify the list that will be used for the 2nd loop.
63. # This is to prevent semantic bugs.
64.
65. # Here the only elements that do exist are the one's THAT DON'T REPEAT
66. # AND THE ONE'S THAT EXIST IN X.
67.
68.