https://kotlinlang.org logo
#getting-started
Title
# getting-started
p

poohbar

10/25/2020, 4:50 PM
something like
lists.chunked(size / n)
s

sergeyb

10/26/2020, 3:20 AM
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

Tobias Berger

10/26/2020, 8:20 AM
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

Michael de Kaste

10/26/2020, 9:08 AM
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

sergeyb

10/26/2020, 9:48 AM
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

ephemient

10/27/2020, 2:41 PM
could perform rounded division for each chunk size to keep them similarly sized
s

sergeyb

10/27/2020, 2:44 PM
wow cool 🙌
3 Views