Guest User

Untitled

a guest
Oct 22nd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. categories = [raw_input("Enter categories: ").split()]
  2.  
  3. width = 0
  4. heights = []
  5.  
  6. for i in xrange(len(categories[0])):
  7. if len(categories[0][i]) > width:
  8. width = len(categories[0][i])
  9. categories[0][i] = [categories[0][i]]
  10.  
  11. def safed(s):
  12. if s[0]!="(":
  13. return s
  14. tmp = s[1:]
  15. if "(" not in tmp or tmp.index("(") < tmp.index(")"):
  16. return s[1:-1]
  17.  
  18. return s
  19.  
  20.  
  21. def merge(a,b):
  22. if b == "conj":
  23. return None
  24. if a == "conj":
  25. nest = 0
  26. b = safed(b)
  27. return "(" + b + ")\(" + b + ")"
  28. if a.endswith("/"+b):
  29. return safed(a[:-len(b)-1])
  30. if a.endswith("/("+b+")"):
  31. return safed(a[:-len(b)-3])
  32. if b.endswith("\\"+a):
  33. return safed(b[:-len(a)-1])
  34. if b.endswith("\\("+a+")"):
  35. return safed(b[:-len(a)-3])
  36.  
  37. return None
  38.  
  39.  
  40. while len(categories[0]) > 1:
  41. categories.insert(0, [[] for i in xrange(len(categories[0]) - 1)])
  42. heights.insert(0,1)
  43. for i in xrange(len(categories[0])):
  44. for ii in xrange(1,len(categories)):
  45. for subx in xrange(len(categories[-ii][i])):
  46. for suby in xrange(len(categories[ii][ii + i])):
  47. x = categories[-ii][i][subx].split('|')
  48. y = categories[ii][ii + i][suby].split('|')
  49. for w in x:
  50. for z in y:
  51. a = merge(w, z)
  52. if a:
  53. categories[0][i].append(a)
  54. if len(a) > width:
  55. width = len(a)
  56. if len(categories[0][i]) > heights[0]:
  57. heights[0] = len(categories[0][i])
  58.  
  59.  
  60.  
  61. print "%d derivations" % len(categories[0][0])
Add Comment
Please, Sign In to add comment