1import itertools
2
3def organize(cars, students):
4 for perm in itertools.permutations(students, len(students)):
5 all_seated = True
6 car_iter = iter(cars)
7 car = next(car_iter)
8 for student in perm:
9 try:
10 car.add_student(student)
11 except:
12 try:
13 car = next(car_iter)
14 except StopIteration:
15 all_seated = False
16 break
17 car.add_student(student)
18 all_seated = student.is_comfy()
19 if not all_seated: break
20 if not all_seated: continue
21 return True
22 return False
.E.E.
======================================================================
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
car = next(car_iter)
StopIteration
======================================================================
ERROR: test_regular_case (test.TesFull)
Test a regular case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/solution.py", line 10, in organize
car.add_student(student)
File "/tmp/helpers.py", line 27, in add_student
raise EnvironmentError('Car is full')
OSError: Car is full
During handling of the above exception, another exception occurred:
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 17, 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=2)
f | 1 | import itertools | f | 1 | import itertools |
2 | 2 | ||||
3 | def organize(cars, students): | 3 | def organize(cars, students): | ||
4 | for perm in itertools.permutations(students, len(students)): | 4 | for perm in itertools.permutations(students, len(students)): | ||
5 | all_seated = True | 5 | all_seated = True | ||
n | 6 | carIter = iter(cars) | n | 6 | car_iter = iter(cars) |
7 | car = next(carIter) | 7 | car = next(car_iter) | ||
8 | for student in perm: | 8 | for student in perm: | ||
9 | try: | 9 | try: | ||
10 | car.add_student(student) | 10 | car.add_student(student) | ||
11 | except: | 11 | except: | ||
12 | try: | 12 | try: | ||
t | 13 | car = next(carIter) | t | 13 | car = next(car_iter) |
14 | except StopIteration: | 14 | except StopIteration: | ||
15 | all_seated = False | 15 | all_seated = False | ||
16 | break | 16 | break | ||
17 | car.add_student(student) | 17 | car.add_student(student) | ||
18 | all_seated = student.is_comfy() | 18 | all_seated = student.is_comfy() | ||
19 | if not all_seated: break | 19 | if not all_seated: break | ||
20 | if not all_seated: continue | 20 | if not all_seated: continue | ||
21 | return True | 21 | return True | ||
22 | return False | 22 | return False |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|