Created
March 19, 2020 15:55
-
-
Save StFS/c940ba02ccf2572d3fb107e78b1a7358 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def numbers = 1..6 | |
def max_splits = 7 | |
count = numbers.size() | |
overflow = count % max_splits | |
pergroup = count.intdiv(max_splits) | |
println "Count: " + count + ", overflow: " + overflow + ", pergroup: " + pergroup | |
source_idx = 0 | |
result = [] | |
splits = Math.min(max_splits, count) | |
0.upto( splits-1 ) { | |
if (it < overflow) { | |
slice_size = pergroup + 1 | |
} else { | |
slice_size = pergroup | |
} | |
result += [numbers[source_idx .. (source_idx + slice_size - 1)]] | |
source_idx += slice_size | |
} | |
println "Result: " + result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment