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)
| f | 1 | def organize(cars_list, students_list): | f | 1 | def 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 True | 4 | return True | ||
| 5 | 5 | ||||
| 6 | current_student = students_list[index] | 6 | current_student = students_list[index] | ||
| 7 | 7 | ||||
| 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 True | 14 | 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 | pass | 18 | pass | ||
| 19 | 19 | ||||
| 20 | return False | 20 | return False | ||
| 21 | 21 | ||||
| 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) | ||
| 24 | 24 | ||||
| t | 25 | # 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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||