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

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

0 точки общо

2 успешни теста
3 неуспешни теста
Код

 1def organize(cars: list, students: list) -> bool:
 2    last_car = 0
 3    used_cars = {student: [] for student in students}
 4    for student in students:
 5        while student.is_comfy() is None:
 6            try:
 7                cars[last_car].add_student(student)
 8                used_cars[student].append(cars[last_car])
 9            except EnvironmentError:
10                last_car += 1
11                if not last_car < len(cars):
12                    return False
13
14    for student in students:
15        while not student.is_comfy():
16            if len(used_cars[student]) == len(cars):
17                return False
18            used_cars[student][-1].remove_student(student)
19            for car in cars:
20                if car in used_cars[student]:
21                    continue
22                car.add_student(student)
23                used_cars[student].append(car)
24                break
25
26    return True

.EEE.
======================================================================
ERROR: 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))
File "/tmp/solution.py", line 7, in organize
cars[last_car].add_student(student)
IndexError: list index out of range

======================================================================
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 18, in organize
used_cars[student][-1].remove_student(student)
IndexError: list index out of range

======================================================================
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 22, in organize
car.add_student(student)
File "/tmp/helpers.py", line 27, in add_student
raise EnvironmentError('Car is full')
OSError: Car is full

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

FAILED (errors=3)

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