Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import combinations
- import re
- X =[1,7,3,4,5,6]
- C = (1,2,3),(3,4,5),(1,2,5),(1,5,6),(1,7,6)
- if len(X) % 3 > 0:
- print('no')
- quit()
- # I will check each possible set of "len(X)//3-combinations" from
- # the list C.
- # This algorithim belongs to Hopee1995x on Reddit
- trip_wire_for_no = 0
- for jj in combinations(C, len(X)//3):
- if len(jj) > 1:
- one_by_one = str(jj)
- # Below, I then convert each combination
- # of jj into an indidvudual list.
- loop_one_by_one = (re.sub("[^0-9,]", "", one_by_one))
- loop_one_by_one = loop_one_by_one.split(',')
- # Below, I convert "strings-of-integers"
- # into int's.
- # (eg. '2' is now converted into 2 in the list)
- convert = list(map(int, loop_one_by_one))
- # Below, I make sure that ALL OF JJ's elements exist in X.
- make_sure_all_elements_exist_in_X = all(elem in convert for elem in X)
- # if make_sure_all_elements_exist_in_X == true, I then loop through the new list. (convert)
- if make_sure_all_elements_exist_in_X:
- for yy in range(0, len(convert)):
- # Below, this statement makes sure that
- #every element in "convert" occurs less than 2-times.
- # So that our X3C solution only contains
- # ONE-ELEMENT-OF-EACH.
- if convert.count(int(convert[yy])) < 2:
- # This statement makes sure that all elements
- #in convert occur once in the list X.
- if X.count(int(convert[yy])) == 1:
- # This statement makes sure that
- # the len(convert) == len(X).
- if len(convert) == len(X):
- print(convert, 'yes')
- trip_wire_for_no = 1
- break
- if trip_wire_for_no == 0:
- print('no')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement