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

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

1 точки общо

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

 1def organize(cars_list, students_list):
 2    def helper(index, assigned_cars):
 3        if index == len(students_list):
 4            return True
 5
 6        current_student = students_list[index]
 7
 8        for car in cars_list:
 9            try:
10                car.add_student(current_student)
11                if all(s.is_comfy() for s in assigned_cars[car]):
12                    assigned_cars[car].append(current_student)
13                    if helper(index + 1, assigned_cars):
14                        return True
15                    assigned_cars[car].remove(current_student)
16                car.remove_student(current_student)
17            except EnvironmentError:
18                pass
19
20        return False
21
22    initial_assigned_cars = {car: [] for car in cars_list}
23    return helper(0, initial_assigned_cars)

...F.
======================================================================
FAIL: test_regular_case (test.TesFull)
Test a regular case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 48, in test_regular_case
anti_rusalov_true(self, all([x.is_comfy() is True for x in students]))
AssertionError: False is not true

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

FAILED (failures=1)

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

f1def organize(cars_list, students_list):f1def organize(cars_list, students_list):
2    def helper(index, assigned_cars):2    def helper(index, assigned_cars):
3        if index == len(students_list):3        if index == len(students_list):
4            return True4            return True
55
6        current_student = students_list[index]6        current_student = students_list[index]
77
8        for car in cars_list:8        for car in cars_list:
9            try:9            try:
10                car.add_student(current_student)10                car.add_student(current_student)
11                if all(s.is_comfy() for s in assigned_cars[car]):11                if all(s.is_comfy() for s in assigned_cars[car]):
12                    assigned_cars[car].append(current_student)12                    assigned_cars[car].append(current_student)
13                    if helper(index + 1, assigned_cars):13                    if helper(index + 1, assigned_cars):
14                        return True14                        return True
15                    assigned_cars[car].remove(current_student)15                    assigned_cars[car].remove(current_student)
16                car.remove_student(current_student)16                car.remove_student(current_student)
17            except EnvironmentError:17            except EnvironmentError:
18                pass18                pass
1919
20        return False20        return False
2121
22    initial_assigned_cars = {car: [] for car in cars_list}22    initial_assigned_cars = {car: [] for car in cars_list}
23    return helper(0, initial_assigned_cars)23    return helper(0, initial_assigned_cars)
2424
t25# class Car:t
26#     def __init__(self):
27#         self.people = 0
28#         self.students = []
29        
30#     def add_student(self, student):
31#         if self.people == 4:
32#             raise EnvironmentError
33#         self.students.append(student)
34#         self.people += 1
35        
36#     def remove_student(self, student):
37#         if student not in self.students:
38#             raise EnvironmentError
39#         self.people -= 1
40#         self.students.remove(student)
41 
42 
43# class Student:
44#     def __init__(self):
45#         self.car = None
46        
47#     def is_comfy(self):
48#         return True
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op