something like `lists.chunked(size / n)`
# getting-started
p
something like
lists.chunked(size / n)
s
what’s wrong with
list.chunked(size/n)
?
Copy code
val s = generateSequence(1) { it + 2 }.take(10)

val list = s.toList()
println(list.toList())
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]

val chunkedList = list.chunked(list.size / 3)
println(chunkedList)
 [[1, 3, 5], [7, 9, 11], [13, 15, 17], [19]]
t
not my question, but assuming you want to divide a list of 91 elements into 10 target lists. That will leave you with 9 Lists of 10 elements and 1 list with only 1 element. That isn't roughly equally sized.
m
the problem with that is that it's really hard to regulate what the standard redistribution should be. if you have 92 elements into 10 target lists, should it be: 1. 10,9,9,9,9,10,9,9,9,9 2. 10,10,9,9,9,9,9,9,9,9 3. 9,9,9,9,9,9,9,9,10,10 so doing the extra work seems logical to me
👍 1
s
I think in all these cases, if no other restriction about redistribution, you can put the remaining items one by one to each bucket starting from the last one as Michael advised above.
e
could perform rounded division for each chunk size to keep them similarly sized
s
wow cool 🙌