Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. __author__ = 'pranav.ambhore'
  2. import random
  3.  
  4. list_items = [2, 6, 8, 9, 15, 21]
  5. list1 = []
  6. list2 = []
  7. to_list1 = []
  8. to_list2 = []
  9.  
  10. list_items = sorted(list_items)
  11.  
  12. list_items = list(reversed(list_items))
  13.  
  14. j = len(list_items) - 1
  15.  
  16. pivote = random.randint(1, j)
  17. list1 = list_items[0: pivote]
  18. list2 = list_items[pivote:]
  19.  
  20. print(list1)
  21. print(list2)
  22.  
  23. diff = sum(list1) - sum(list2)
  24. pre_diff = 0
  25.  
  26. count = 1
  27. while count == 1:
  28. count = 0
  29. if diff != 0:
  30. for item in list2:
  31. if item <= (diff * -1):
  32. to_list1.append(item)
  33. list2.remove(item)
  34. count += 1
  35. break
  36. for item in list1:
  37. if item <= diff:
  38. to_list2.append(item)
  39. list1.remove(item)
  40. count += 1
  41. break
  42. pre_diff = diff
  43. diff = sum(list1) + sum(to_list1) - sum(list2) - sum(to_list2)
  44.  
  45. list1 = list1 + to_list1
  46. print(list1)
  47. list2 = list2 + to_list2
  48. print(list2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement