diff --git a/tasks/easy/collections/partiphify.toml b/tasks/easy/collections/partiphify.toml index 79efafa..18bfab6 100644 --- a/tasks/easy/collections/partiphify.toml +++ b/tasks/easy/collections/partiphify.toml @@ -17,30 +17,27 @@ description_ru = """ limits = """ - $1 \\leq |\\text{numbers}| \\leq 100$ -- $1 \\leq \\text{parts} \\leq |\\text{numbers}|$ +- $1 \\leq \\text{parts} \\leq 100$ - $-100 \\leq \\text{numbers}[i] \\leq 100$ """ solution = """ def solution(numbers: list, parts: int) -> list: - import math - - if not numbers: - return [] - - part_size = math.ceil(len(numbers) / parts) + length = len(numbers) + part_size, big_parts = divmod(length, parts) + small_parts = parts - big_parts result = [] - - for i in range(0, len(numbers), part_size): - part = numbers[i:i + part_size] - if part: - result.append(part) - + for i in range(big_parts): + result.append(numbers[:part_size+1]) + numbers = numbers[part_size+1:] + for i in range(small_parts): + result.append(numbers[:part_size]) + numbers = numbers[part_size:] return result """ examples = """ -solution([1], 2) == [[1]] +solution([1], 2) == [[1], []] solution([1, 2, 3], 3) == [[1], [2], [3]] solution([1, 2, 3, 4, 5], 2) == [[1, 2, 3], [4, 5]] """ @@ -67,7 +64,7 @@ name = "integer" [[asserts]] arguments = [[1], 2] comment = "One element two parts" -expected = [[1]] +expected = [[1], []] [[asserts]] arguments = [[1, 2, 3], 3] @@ -92,7 +89,7 @@ expected = [[1, 2], [3, 4], [5, 6]] [[asserts]] arguments = [[1, 2, 3, 4, 5, 6, 7], 3] comment = "Seven into three" -expected = [[1, 2, 3], [4, 5, 6], [7]] +expected = [[1, 2, 3], [4, 5], [6, 7]] [[asserts]] arguments = [[1, 2], 1] @@ -117,7 +114,7 @@ expected = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [[asserts]] arguments = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3] comment = "Ten into three" -expected = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]] +expected = [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]] [[asserts]] arguments = [[1], 1] @@ -142,7 +139,7 @@ expected = [[1, 2, 3, 4], [5, 6, 7]] [[asserts]] arguments = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 4] comment = "Ten into four" -expected = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]] +expected = [[1, 2, 3], [4, 5, 6], [7, 8], [9, 10]] [[asserts]] arguments = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], 3] @@ -171,8 +168,8 @@ expected = [[1, 2], [3, 4], [5]] [[asserts]] arguments = [[1, 2, 3, 4, 5, 6, 7, 8, 9], 4] -comment = "Nine into four (ceil gives 3 parts)" -expected = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] +comment = "Nine into four" +expected = [[1, 2, 3], [4, 5], [6, 7], [8, 9]] [[asserts]] arguments = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5] @@ -182,12 +179,12 @@ expected = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] [[asserts]] arguments = [[1, 2, 3, 4], 3] comment = "Four into three" -expected = [[1, 2], [3, 4]] +expected = [[1, 2], [3], [4]] [[asserts]] arguments = [[1, 2, 3, 4, 5, 6], 4] comment = "Six into four" -expected = [[1, 2], [3, 4], [5, 6]] +expected = [[1, 2], [3, 4], [5], [6]] [[asserts]] arguments = [[1, 2, 3, 4, 5, 6, 7], 4] @@ -213,3 +210,18 @@ expected = [[1], [2]] arguments = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2] comment = "Ten into two" expected = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]] + +[[asserts]] +arguments = [[1, 2, 3, 4, 5, 6, 7, 8, 9], 7] +comment = "Nine into seven" +expected = [[1, 2], [3, 4], [5], [6], [7], [8], [9]] + +[[asserts]] +arguments = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 5] +comment = "Eleven into five" +expected = [[1, 2, 3], [4, 5], [6, 7], [8, 9], [10, 11]] + +[[asserts]] +arguments = [[1, 2], 5] +comment = "Two into five" +expected = [[1], [2], [], [], []]