Skip to content

Instantly share code, notes, and snippets.

@caius
Created November 1, 2018 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caius/e2f75f0f1a334994700bdbf78c3fdcee to your computer and use it in GitHub Desktop.
Save caius/e2f75f0f1a334994700bdbf78c3fdcee to your computer and use it in GitHub Desktop.
# 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