1def is_valid(combination):
2 for car in combination:
3 for student in car:
4 if not student.is_comfy():
5 return False
6 return True
7
8def generate_comb(list_cars, list_students, combination):
9 if len(list_students) == 0:
10 return is_valid(combination)
11
12 for i, car in enumerate(list_cars):
13 if len(combination[i]) < 4:
14 combination[i].append(list_students[0])
15 if generate_comb(list_cars, list_students[1:], combination):
16 return True
17 combination[i].pop()
18
19 return False
20
21
22def organize(list_cars, list_students):
23 return (generate_comb(list_students, list_cars,
24 [[] for _ in range(len(list_cars))]))
25
EFEEE
======================================================================
ERROR: test_big_input (test.TesFull)
Test a big case to ensure no huge bruteforcing.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 90, in test_big_input
anti_rusalov_true(self, organize(cars, students))
File "/tmp/solution.py", line 23, in organize
return (generate_comb(list_students, list_cars,
File "/tmp/solution.py", line 15, in generate_comb
if generate_comb(list_cars, list_students[1:], combination):
File "/tmp/solution.py", line 15, in generate_comb
if generate_comb(list_cars, list_students[1:], combination):
File "/tmp/solution.py", line 15, in generate_comb
if generate_comb(list_cars, list_students[1:], combination):
[Previous line repeated 1 more time]
File "/tmp/solution.py", line 10, in generate_comb
return is_valid(combination)
File "/tmp/solution.py", line 4, in is_valid
if not student.is_comfy():
AttributeError: 'Car' object has no attribute 'is_comfy'
======================================================================
ERROR: test_real_case_false (test.TesFull)
Test a real case for False.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 36, in test_real_case_false
anti_rusalov_false(self, organize(cars, students))
File "/tmp/solution.py", line 23, in organize
return (generate_comb(list_students, list_cars,
File "/tmp/solution.py", line 15, in generate_comb
if generate_comb(list_cars, list_students[1:], combination):
File "/tmp/solution.py", line 10, in generate_comb
return is_valid(combination)
File "/tmp/solution.py", line 4, in is_valid
if not student.is_comfy():
AttributeError: 'Car' object has no attribute 'is_comfy'
======================================================================
ERROR: test_regular_case (test.TesFull)
Test a regular case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 47, in test_regular_case
anti_rusalov_true(self, organize(cars, students))
File "/tmp/solution.py", line 23, in organize
return (generate_comb(list_students, list_cars,
File "/tmp/solution.py", line 15, in generate_comb
if generate_comb(list_cars, list_students[1:], combination):
File "/tmp/solution.py", line 15, in generate_comb
if generate_comb(list_cars, list_students[1:], combination):
File "/tmp/solution.py", line 10, in generate_comb
return is_valid(combination)
File "/tmp/solution.py", line 4, in is_valid
if not student.is_comfy():
AttributeError: 'Car' object has no attribute 'is_comfy'
======================================================================
ERROR: test_single_solution_case (test.TesFull)
Test a single-solution case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 65, in test_single_solution_case
anti_rusalov_true(self, organize(cars, students))
File "/tmp/solution.py", line 23, in organize
return (generate_comb(list_students, list_cars,
File "/tmp/solution.py", line 15, in generate_comb
if generate_comb(list_cars, list_students[1:], combination):
File "/tmp/solution.py", line 15, in generate_comb
if generate_comb(list_cars, list_students[1:], combination):
File "/tmp/solution.py", line 10, in generate_comb
return is_valid(combination)
File "/tmp/solution.py", line 4, in is_valid
if not student.is_comfy():
AttributeError: 'Car' object has no attribute 'is_comfy'
======================================================================
FAIL: test_empty (test.TesFull)
Test with empty cars.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 27, in test_empty
anti_rusalov_false(self, organize([], students))
AssertionError: True is not false
----------------------------------------------------------------------
Ran 5 tests in 0.001s
FAILED (failures=1, errors=4)
![]()
Виктор Бечев
07.12.2023 18:42Brute force, backtracking алгоритъм, наречи го както щеш, но да, не е логическа задача с тривиално решение, просто трябва код, който да минава през вариантите докато не намери правилен или не ги изчерпи.
|
![]()
Стелиан Витанов
07.12.2023 16:03Опитах каквото можех да измисля, но съм наясно, че сигурно не работи. Да не би начинът да е с brute force?
|