Skip to content

'allocation_content_length' #1808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 20, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
'allocation_content_length'
  • Loading branch information
wind-Lv committed Mar 20, 2020
commit 08e66da856a87b249d39829a860df1a2f087f02d
39 changes: 39 additions & 0 deletions maths/allocation_content_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#-*- coding:utf-8 -*-


def allocation_content_length(content_length, portioning):
"""
>>> content_length = 16647
>>> portioning = 4
>>> shares = content_length // portioning

>>> f'0-{shares*1}'
'0-4161'
>>> f'{shares*1+1}-{shares*2}'
'4162-8322'
>>> f'{shares*2+1}-{shares*3}'
'8323-12483'
>>> f'{shares*3+1}-{shares*4}'
'12484-16647'
"""

shares = content_length // portioning

allocation_list = [f'0-{shares*1}']
for i in range(1,portioning-1):
length = f'{shares*i+1}-{shares*(i+1)}'
allocation_list.append(length)
allocation_list.append(f'{(shares*(portioning-1))+1}-{content_length}')

return allocation_list


def main():
the_list = allocation_content_length(16647,4)
print(the_list)


if __name__ == '__main__':
main()