Guest User

Untitled

a guest
Feb 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. import random
  2.  
  3. data = {
  4. 'students' : ['allie','AndreaAngquist', 'andrew.c.chao','arielhaney','deepaks', 'donghyuk-jung', 'Elliot', 'emilybarabas', 'gahernandez', 'gshapiro','icheung','jenmwang', 'Matt Acalin','natarajan','sam', 'vimalkini', 'brendanmcurran','awootton44','karthikv','gaurav.shetti', 'rami'],
  5.  
  6. 'project_1' : [['brendanmcurran', 'arielhaney', 'awootton44'], ['AndreaAngquist','gshapiro','andrew.c.chao'],['achung','arielhaney','donghyuk-jung'],['gahernandez','icheung','Matt Acalin','allie'],['gaurav.shetti','vimalkini'],
  7. ['sam','Elliot','jenmwang'],
  8. ['natarajan','karthikv'],
  9. ['rami','deepaks','saghar'],],
  10.  
  11. 'project_2' : [['sam','allie','andrew.c.chao'],['gahernandez','arielhaney','jenmwang'],['vimalkini','icheung'],
  12. ['brendanmcurran','karthikv','Matt Acalin'], ['natarajan','gaurav.shetti'],['AndrewAngquist','Elliot','awootton44','rami'],['deepaks','emilybarabas','gshapiro','donghyuk-jung']],
  13.  
  14. 'project_3' : [['rami','icheung','awootton44'],['brendanmcurran','arielhaney','natarajan'],['Elliot','jenmwang','andrew.c.chao'],['deepaks','allie','gaurav.shetti'],['sam','gahernandez','gshapiro'],
  15. ['Matt Acalin','AndreaAngquist','awootton44'],
  16. ['vimalkini','donghyuk-jung','karthikv']]
  17. }
  18.  
  19. students_list = data['students']
  20.  
  21. group_size = 3
  22.  
  23. def main():
  24. print "New groups: "
  25. while len(students_list) > group_size:
  26. root_student = students_list.pop(0)
  27. make_group([root_student])
  28. print "Remainder: " + serial(students_list)
  29.  
  30.  
  31. def make_group(current_group,counter=0):
  32. if len(current_group) == group_size:
  33. print serial(current_group)
  34. elif counter > 10 or len(students_list) < 1:
  35. print 'Stalled on group [' + serial(current_group) + '] with remainder [' + serial(students_list) + ']'
  36. else:
  37. index = random.randint(0,len(students_list)-1)
  38. new_student = students_list[index]
  39. if new_to_group(new_student,current_group):
  40. current_group.append(new_student)
  41. students_list.pop(index)
  42. make_group(current_group,counter)
  43. else:
  44. make_group(current_group,counter+1)
  45.  
  46. def new_to_group(new_student,group):
  47. is_new = True
  48. for student in group:
  49. if have_worked_together(student,new_student):
  50. is_new = False
  51. return is_new
  52.  
  53. def have_worked_together(student1, student2):
  54. fact = False
  55. # if any function call returns True, fact will become True
  56. fact = fact or work_together_helper(data['project_1'],student1,student2)
  57. fact = fact or work_together_helper(data['project_2'],student1,student2)
  58. fact = fact or work_together_helper(data['project_3'],student1,student2)
  59. return fact
  60.  
  61. def work_together_helper(project, student1, student2):
  62. for team in project:
  63. if student1 in team:
  64. if student2 in team:
  65. return True
  66. break
  67. return False
  68.  
  69. def has_worked_with(student):
  70. projects=[data['project_1'],data['project_2'],data['project_3']]
  71. worked_with_dico = {}
  72. worked_with_list = []
  73. for project in projects:
  74. for team in project:
  75. if student in team:
  76. for person in team:
  77. if person != student and not person in worked_with_dico:
  78. worked_with_list.append(person)
  79. worked_with_dico[person] = 1
  80. return worked_with_list
  81.  
  82. def serial(list):
  83. if type(list) == type(str()):
  84. return list
  85. elif list:
  86. s = ''
  87. for item in list:
  88. s = s + item + ', '
  89. return s
  90. else:
  91. return ""
Add Comment
Please, Sign In to add comment