-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday13.py
57 lines (44 loc) · 1.09 KB
/
day13.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
x = list(map(str.splitlines, open('input_day13.txt').read().strip().split("\n\n")))
def f(x, y):
if type(x) == int:
if type(y) == int:
return x - y
else:
return f([x], y)
else:
if type(y) == int:
return f(x, [y])
for a, b in zip(x, y):
v = f(a, b)
if v:
return v
return len(x) - len(y)
t = 0
for i, (a, b) in enumerate(x):
if f(eval(a), eval(b)) < 0:
t += i + 1
print('the answer 1:'.title(), t)
def f(x, y):
if type(x) == int:
if type(y) == int:
return x - y
else:
return f([x], y)
else:
if type(y) == int:
return f(x, [y])
for a, b in zip(x, y):
v = f(a, b)
if v:
return v
return len(x) - len(y)
x = list(map(eval, open('input_day13.txt').read().split()))
i2 = 1
i6 = 2
for a in x:
if f(a, [[2]]) < 0:
i2 += 1
i6 += 1
elif f(a, [[6]]) < 0:
i6 += 1
print('the answer 2:', i2 * i6)