Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- categories = [raw_input("Enter categories: ").split()]
- width = 0
- heights = []
- for i in xrange(len(categories[0])):
- if len(categories[0][i]) > width:
- width = len(categories[0][i])
- categories[0][i] = [categories[0][i]]
- def safed(s):
- if s[0]!="(":
- return s
- tmp = s[1:]
- if "(" not in tmp or tmp.index("(") < tmp.index(")"):
- return s[1:-1]
- return s
- def merge(a,b):
- if b == "conj":
- return None
- if a == "conj":
- nest = 0
- b = safed(b)
- return "(" + b + ")\(" + b + ")"
- if a.endswith("/"+b):
- return safed(a[:-len(b)-1])
- if a.endswith("/("+b+")"):
- return safed(a[:-len(b)-3])
- if b.endswith("\\"+a):
- return safed(b[:-len(a)-1])
- if b.endswith("\\("+a+")"):
- return safed(b[:-len(a)-3])
- return None
- while len(categories[0]) > 1:
- categories.insert(0, [[] for i in xrange(len(categories[0]) - 1)])
- heights.insert(0,1)
- for i in xrange(len(categories[0])):
- for ii in xrange(1,len(categories)):
- for subx in xrange(len(categories[-ii][i])):
- for suby in xrange(len(categories[ii][ii + i])):
- x = categories[-ii][i][subx].split('|')
- y = categories[ii][ii + i][suby].split('|')
- for w in x:
- for z in y:
- a = merge(w, z)
- if a:
- categories[0][i].append(a)
- if len(a) > width:
- width = len(a)
- if len(categories[0][i]) > heights[0]:
- heights[0] = len(categories[0][i])
- print "%d derivations" % len(categories[0][0])
Add Comment
Please, Sign In to add comment