-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc2213.py
53 lines (44 loc) · 1.15 KB
/
aoc2213.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
import functools
path = '_inputs/2213.0'
# path = '_inputs/2213.1'
a = []
l = []
aa = [] # part 2
def cmp(l, r):
if type(l) is list and type(r) is list:
for a, b in zip(l, r):
res = cmp(a, b)
if res != 0:
return res
continue
return len(l) - len(r)
elif type(l) is list and type(r) is int:
return cmp(l, [r])
elif type(l) is int and type(r) is list:
return cmp([l], r)
elif type(l) is int and type(r) is int:
return l - r
with open(path) as file:
for line in file:
line = line.strip()
if line == '':
a.append(l)
l = []
else:
l.append(eval(line))
if line != '':
aa.append(eval(line))
a.append(l)
aa.append([[2]]) # part 2
aa.append([[6]])
aa.sort(key=functools.cmp_to_key(cmp))
res = 0
for index, (a, b) in enumerate(a):
# print("i:", index, a, b, "cmp:", cmp(a, b))
if cmp(a, b) < 0:
res += index + 1
# for l in aa:print(l)
# print( aa.index([[2]]), aa.index([[6]]) )
res2 = (1 + aa.index([[2]])) * (1 + aa.index([[6]]))
print("Star 1:", res)
print("Star 2:", res2)