Last active
February 6, 2022 11:19
-
-
Save KAnanev/382774e5fd79d4c453c87e44d1587ea4 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
# Дан массив N и число k <= len(N)/2 | |
# Как разбить массив N на k подмассивов так, | |
# чтобы длина самого длинного и самого короткого | |
# подмассивов отличалась не более чем на 1. | |
def main(arr, n): | |
tmp_arr = [] | |
lenght_arr = len(arr) | |
lenght_sub_arr = lenght_arr // n | |
rem_div = lenght_arr % n | |
start = 0 | |
for _ in range(n): | |
if rem_div: | |
end = start + lenght_sub_arr + 1 | |
rem_div = rem_div - 1 | |
else: | |
end = start + lenght_sub_arr | |
tmp_arr.append(arr[start:end]) | |
start = end | |
return tmp_arr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment