Created
November 1, 2018 10:59
-
-
Save caius/e2f75f0f1a334994700bdbf78c3fdcee to your computer and use it in GitHub Desktop.
This file contains 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
# Content-Length, Worker index, Worker total count | |
length, index, count = ARGV.first(3).map(&method(:Integer)) | |
slice, remainder = length.divmod(count) | |
min = index * slice | |
max = if index == (count - 1) | |
# Final slice finishes on total size | |
length | |
else | |
# One less than next slice starting point | |
((index + 1) * slice) - 1 | |
end | |
puts "#{min}-#{max}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment