Advertisement
nher1625

Almost_even

Apr 4th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. __author__ = 'Neys'
  2. from math import floor
  3.  
  4. def splitInteger(num,parts):
  5.     splits = []
  6.     count = parts
  7.     if num % parts == 0:
  8.         splits = [int(num/parts) for x in range(parts)]
  9.         print(splits)
  10.     else:
  11.         while len(splits) < count:
  12.             splits.append( int(round(num/parts)) )
  13.             num -= 0.5
  14.             if num % parts == 0:
  15.                 parts -= 1
  16.                 while len(splits) < count:
  17.                     splits.append( int(round(num/parts)) )
  18.             #print(num)
  19.         print(splits)
  20.  
  21. def splitIntegerFuck(num,parts): print( [num/parts]*(parts-num%parts)+[num/parts+1]*(num%parts) )
  22.  
  23. splitIntegerFuck(20,6)
  24. splitIntegerFuck(10,1)
  25. splitIntegerFuck(2, 2)
  26. splitIntegerFuck(11,3)
  27. splitIntegerFuck(20, 5)
  28.  
  29. splitInteger(99,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement