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

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

0 точки общо

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

 1from itertools import permutations
 2
 3def organize(cars, students):
 4    if len(cars) < 4 * len(students):
 5        return False
 6    seats = []
 7    for num in range(0, len(cars)):
 8        for _ in range(1,5):
 9            seats.append(num)
10    for order in permutations(seats, len(students)):
11        index = 0
12        for num in order:
13            cars[num].add_student(students[index])
14            index += 1
15        for student in students:
16            if student.is_comfy() is False:
17                break
18        else:
19            return True
20        index = 0
21        for num in order:
22            cars[num].remove_student(students[index])
23            index += 1
24    return False  

F..FF
======================================================================
FAIL: 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))
AssertionError: False is not true

======================================================================
FAIL: 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))
AssertionError: False is not true

======================================================================
FAIL: 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))
AssertionError: False is not true

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

FAILED (failures=3)

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

f1from itertools import permutationsf1from itertools import permutations
22
3def organize(cars, students):3def organize(cars, students):
4    if len(cars) < 4 * len(students):4    if len(cars) < 4 * len(students):
5        return False5        return False
n6    n
7    seats = []6    seats = []
8    for num in range(0, len(cars)):7    for num in range(0, len(cars)):
9        for _ in range(1,5):8        for _ in range(1,5):
10            seats.append(num)9            seats.append(num)
n11 n
12    for order in permutations(seats, len(students)):10    for order in permutations(seats, len(students)):
13        index = 011        index = 0
14        for num in order:12        for num in order:
15            cars[num].add_student(students[index])13            cars[num].add_student(students[index])
16            index += 114            index += 1
n17        n
18        for student in students:15        for student in students:
19            if student.is_comfy() is False:16            if student.is_comfy() is False:
20                break17                break
21        else:18        else:
22            return True19            return True
n23        n
24        index = 020        index = 0
25        for num in order:21        for num in order:
26            cars[num].remove_student(students[index])22            cars[num].remove_student(students[index])
t27            index += 1  t23            index += 1
28 
29    return False  24    return False  
3025
3126
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op