Skip to content
Open
Changes from all commits
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
56 changes: 34 additions & 22 deletions tasks/easy/collections/partiphify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
"""
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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], [], [], []]