Предизвикателства > Осмодекемврийско пътуване > Решения > Решението на Пламена Николова

Резултати
0 точки от тестове
0 точки от учител

0 точки общо

1 успешни теста
4 неуспешни теста
Код

 1def organize(cars, students):
 2    def are_students_happy(student1, student2):
 3        return (
 4            (student1.smoke or not student2.smoke) and
 5            (student1.chalga or not student2.chalga) and
 6            (student1.cold is None or not student2.cold)
 7        )
 8
 9    def can_add_students_to_car(car, students):
10        return all(car.add_student(student) for student in students)
11
12    for car in cars:
13        for student in students:
14            if student.car:
15                continue
16
17            try:
18                car.add_student(student)
19            except EnvironmentError:
20                continue
21
22            compatible_students = [s for s in students if are_students_happy(student, s) and not s.car]
23            if can_add_students_to_car(car, compatible_students):
24                return True
25            else:
26                car.remove_student(student)
27
28    return False

E.FFE
======================================================================
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
if can_add_students_to_car(car, compatible_students):
File "/tmp/solution.py", line 10, in can_add_students_to_car
return all(car.add_student(student) for student in students)
File "/tmp/solution.py", line 10, in <genexpr>
return all(car.add_student(student) for student in students)
File "/tmp/helpers.py", line 27, in add_student
raise EnvironmentError('Car is full')
OSError: Car is full

======================================================================
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
if can_add_students_to_car(car, compatible_students):
File "/tmp/solution.py", line 10, in can_add_students_to_car
return all(car.add_student(student) for student in students)
File "/tmp/solution.py", line 10, in <genexpr>
return all(car.add_student(student) for student in students)
File "/tmp/helpers.py", line 27, in add_student
raise EnvironmentError('Car is full')
OSError: Car is full

======================================================================
FAIL: 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))
AssertionError: True is not false

======================================================================
FAIL: 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))
AssertionError: False is not true

----------------------------------------------------------------------
Ran 5 tests in 0.001s

FAILED (failures=2, errors=2)

Дискусия
История
Това решение има само една версия.