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

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

0 точки общо

0 успешни теста
5 неуспешни теста
Код

 1class organize:
 2    def __call__(self, cars, students):
 3        def try_place_students(index):
 4            if index == len(students):
 5                return all(student.is_comfy() for student in students)
 6
 7            for car in cars:
 8                try:
 9                    car.add_student(students[index])
10                    if try_place_students(index + 1):
11                        return True
12                    car.remove_student(students[index])
13                except EnvironmentError:
14                    continue
15
16            return False
17
18        return try_place_students(0)

EEEEE
======================================================================
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))
TypeError: organize() takes no arguments

======================================================================
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))
TypeError: organize() takes no arguments

======================================================================
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))
TypeError: organize() takes no arguments

======================================================================
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))
TypeError: organize() takes no arguments

======================================================================
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))
TypeError: organize() takes no arguments

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

FAILED (errors=5)

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

t1class Organizer:t1class organize:
2    def __call__(self, cars, students):2    def __call__(self, cars, students):
3        def try_place_students(index):3        def try_place_students(index):
4            if index == len(students):4            if index == len(students):
5                return all(student.is_comfy() for student in students)5                return all(student.is_comfy() for student in students)
66
7            for car in cars:7            for car in cars:
8                try:8                try:
9                    car.add_student(students[index])9                    car.add_student(students[index])
10                    if try_place_students(index + 1):10                    if try_place_students(index + 1):
11                        return True11                        return True
12                    car.remove_student(students[index])12                    car.remove_student(students[index])
13                except EnvironmentError:13                except EnvironmentError:
14                    continue14                    continue
1515
16            return False16            return False
1717
18        return try_place_students(0)18        return try_place_students(0)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op