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

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

1 точки общо

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

 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)

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

f1import itertoolsf1import itertools
22
3def organize(cars, students):3def organize(cars, students):
4    for perm in itertools.permutations(students, len(students)):4    for perm in itertools.permutations(students, len(students)):
5        all_seated = True5        all_seated = True
n6        carIter = iter(cars)n6        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:
t13                    car = next(carIter)t13                    car = next(car_iter)
14                except StopIteration:14                except StopIteration:
15                    all_seated = False15                    all_seated = False
16                    break16                    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: break19            if not all_seated: break
20        if not all_seated: continue20        if not all_seated: continue
21        return True21        return True
22    return False22    return False
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op