-
Notifications
You must be signed in to change notification settings - Fork 0
/
13-2.py
65 lines (48 loc) · 1.36 KB
/
13-2.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
data = []
with open(f"13.txt", "r") as file:
data = file.read().splitlines()
data = list(filter(None, data))
for i, row in enumerate(data):
data[i] = eval(row)
def compare_lists(left, right):
#print(f" Compare: {left} vs {right}")
if isinstance(left, int) and isinstance(right, list):
left = [left]
if isinstance(left, list) and isinstance(right, int):
right = [right]
if isinstance(left, int) and isinstance(right, int):
if left < right:
return 1
if left > right:
return 0
return 2
i = 0
while i < len(left) and i < len(right):
match compare_lists(left[i], right[i]):
case 0:
return 0
case 1:
return 1
case 2:
i += 1
continue
if i == len(left):
if len(left) == len(right):
return 2
return 1
return 0
def sort(data):
n = len(data)
for i in range(n):
sorted = True
for j in range(n-i-1):
if compare_lists(data[j], data[j+1]) == 0:
data[j], data[j+1] = data[j+1], data[j]
sorted = False
if sorted:
break
return data
data.append([[2]])
data.append([[6]])
data = sort(data)
print(f"{(data.index([[2]])+1)*(data.index([[6]])+1)} ")