-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-1-disorderly-escape.py
47 lines (32 loc) · 1.17 KB
/
4-1-disorderly-escape.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from itertools import permutations, combinations
import numpy as np
# NOT COMPLETE
def solution(w, h, s):
# Your code here
# print("Permutations")
# for i in list(permutations(s * w, w * h)):
# print("permutation", i)
result_pairs = set()
set_of_combinations = (set(combinations(list(range(s)) * w * h, w * h)))
# list_of_set_of_combinations = list(set_of_combinations)
for i in set_of_combinations:
result_pairs.add(i)
result_pairs = [np.array(list(i)).reshape((w, h))
for i in list(result_pairs)]
formatted_pairs = []
if w != h:
if w < h:
for i in result_pairs:
zeros = np.zeros(h)
formatted_pairs.append(np.insert(i, i.shape[0], zeros, axis=0))
else:
for i in result_pairs:
zeros = np.zeros((w, 1))
formatted_pairs.append(np.column_stack((i, zeros)))
if w == h:
formatted_pairs = result_pairs
eigen_values = {tuple(sorted((np.linalg.eigvals(i)))): i for i in formatted_pairs}
return len(eigen_values)
print(solution(2, 2, 2))
print(solution(2, 3, 4))
# solution(2, 3, [0, 1, 2, 3])