-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
'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
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
08e66da
'allocation_content_length'
wind-Lv 5eff5b8
'allocation_number'
wind-Lv 47a16e7
Delete allocation_content_length.py
wind-Lv a2c3f9c
Update allocation_number.py
wind-Lv f89fd39
Update allocation_number.py
wind-Lv 6a7333b
number_of_bytes and partitions
cclauss 9cff42c
Update allocation_number.py
cclauss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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() | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#-*- coding:utf-8 -*- | ||
|
||
|
||
def allocation_num(num, x) -> int: | ||
""" | ||
Divide the numbers into x parts. | ||
|
||
parameter | ||
------------ | ||
: param num: the number | ||
: param x: number of copies | ||
|
||
return | ||
------------ | ||
: return: split completed list | ||
|
||
example | ||
------------ | ||
>>> allocation_num(16647, 4) | ||
['0-4161', '4162-8322', '8323-12483', '12484-16647'] | ||
|
||
>>> allocation_num(888, 888) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: param x can't past or be equal to the param num! | ||
|
||
>>> allocation_num(888, 111) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: param x can't past or be equal to the param num! | ||
""" | ||
|
||
|
||
if x >= num: | ||
raise ValueError('param x can\'t past or be equal to the param num!') | ||
|
||
shares = num // x | ||
|
||
allocation_list = [f'0-{shares*1}'] | ||
for i in range(1,x-1): | ||
length = f'{shares*i+1}-{shares*(i+1)}' | ||
allocation_list.append(length) | ||
allocation_list.append(f'{(shares*(x-1))+1}-{num}') | ||
|
||
return allocation_list | ||
|
||
|
||
if __name__ == '__main__': | ||
the_list = allocation_num(888,888) | ||
print(the_list) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the mypy output in the Travis CI log
https://github.com/TheAlgorithms/Python/blob/master/Travis_CI_tests_are_failing.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 4 says that the function returns an
int
but line 26 says that we expect alist
ofstr
. Line 26 is correct and line 4 is wrong.$ mypy --ignore-missing-imports .