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

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

1 точки общо

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

 1def organize(cars, students):
 2
 3    free_students = students.copy()
 4
 5    def is_valid_configuration():
 6        for car in cars:
 7            for student in car.students:
 8                if not student.is_comfy():
 9                    return False
10        return True
11
12    if not is_valid_configuration():
13        return False
14
15    for car in cars:
16        while len(car.students) < car.CAPACITY and free_students:
17            student = free_students.pop()
18            try:
19                car.add_student(student)
20            except EnvironmentError:
21                free_students.append(student)
22
23    if not is_valid_configuration():
24        return False
25
26    return True

.F..F
======================================================================
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

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

----------------------------------------------------------------------
Ran 5 tests in 0.000s

FAILED (failures=2)

Дискусия
История

f1def organize(cars, students):f1def organize(cars, students):
nn2 
3    free_students = students.copy()
4 
5    def is_valid_configuration():
6        for car in cars:
7            for student in car.students:
8                if not student.is_comfy():
9                    return False
10        return True
11 
12    if not is_valid_configuration():
13        return False
14 
2    for car in cars:15    for car in cars:
n3        for student in students:n16        while len(car.students) < car.CAPACITY and free_students:
17            student = free_students.pop()
4            try:18            try:
5                car.add_student(student)19                car.add_student(student)
n6                if all(passenger.is_comfy() for passenger in car.passengers):n
7                    return True
8            except EnvironmentError:20            except EnvironmentError:
n9                passn
10            finally:
11                car.remove_student(student)21                free_students.append(student)
1222
tt23    if not is_valid_configuration():
13    return False24        return False
25 
26    return True
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op