Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. y = var('y')
  2. '''
  3. Group Members
  4. =============
  5. '''
  6.  
  7. userids = ['Thormundur15'] # fill in this array with strings of usernames
  8. def m5p1(G):
  9. '''Return the size of the largest clique
  10. '''
  11. maxcount = 1
  12. for i in G:
  13. stack = [i]
  14. for j in G[i]:
  15. if(set(stack) <= set(G[j])):
  16. stack.append(j)
  17. if(len(stack) > maxcount):
  18. maxcount = len(stack)
  19. return maxcount
  20.  
  21. def myfunction(stack, constack, G):
  22. diff = list(set(stack) - set(G))
  23. for i in diff:
  24. if(i not in stack and i not in constack):
  25. newstack [i]
  26. newconstack = []
  27. for j in stack:
  28. newstack.append(j)
  29. for j in constack:
  30. newconstack.append(j)
  31. for j in G[i]:
  32. newconstack.append(j)
  33. myfunction(newstack, newconstack, G)
  34. return len(stack)
  35.  
  36. def m5p2(G):
  37. '''Return the size of the largest independent set
  38. '''
  39. largest = 1
  40. for i in G:
  41. independentSet = [i]
  42. listSC = [i]
  43. for k in G[i]:
  44. listSC.append(k)
  45. count = 0
  46. oArr = G.copy()
  47. for k in range(0, i):
  48. temp = oArr[0]
  49. for j in xrange(0, len(oArr)-1):
  50. oArr[j] = oArr[j+1]
  51. oArr[len(oArr)-1] = temp
  52. for k in oArr:
  53. if(k not in listSC):
  54. independentSet.append(k)
  55. count += 1
  56. if(k in independentSet):
  57. for j in oArr[k]:
  58. listSC.append(j)
  59. if(largest < count):
  60. largest = count
  61. return largest
  62.  
  63. def lowCost(U, S, cost, Allcost):
  64. if(len(U) == 0):
  65. Allcost.append(cost)
  66. return cost
  67. else:
  68. for i in range(len(S)):
  69. for j in range(len(S[i])):
  70. if(S[i][j] in U):
  71. lowCost(list(set(U) - set(S[i])), S, cost+1, Allcost)
  72. break
  73. return min(Allcost)
  74.  
  75. def m5p3(U, S):
  76. '''Return the lowest number of subsets from S to cover U
  77. '''
  78. return lowCost(U, S, 0, [])
  79.  
  80. def m5p4(xmin, xmax, ymin, ymax):
  81. '''Return a lambda function for the square bounded by xmin-xmax and ymin-ymax
  82. '''
  83. return lambda px, py: px >= xmin and px <= xmax and py >= ymin and py <= ymax
  84.  
  85. def m5p5(x0, y0, r):
  86. '''Return a lambda function for the square with center (x0, y0) and side length 2r
  87. '''
  88. return lambda px, py: px >= x0 - r and px <= x0 + r and py >= y0 - r and py <= y0 + r
  89.  
  90. def m5p6(x0, y0, r):
  91. '''Return a lambda function for the disc with center (x0, y0) and radius r
  92. '''
  93. return lambda px, py: True
  94.  
  95. def m5p7((a0, b0, r), n=5000, xmin=-1, xmax=1, ymin=-1, ymax=1):
  96. '''Return an approximation of the area covered by P (a disc) inside the rectangle
  97. '''
  98. return -1
  99.  
  100. def m5p8(f, n=1000, xmin=-1, xmax=1, ymin=-1, ymax=1, zmax=1):
  101. '''Return an approximation of the volume between the function and the xy-plane
  102. '''
  103. return -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement