-
Notifications
You must be signed in to change notification settings - Fork 1
/
03.py
44 lines (33 loc) · 818 Bytes
/
03.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
"""--- Day 3: Squares With Three Sides ---"""
import re
with open("input/03.txt", "r") as f:
valid_1 = valid_2 = 0
a, b, c = [], [], []
for instruction in f:
sides = [int(x) for x in re.findall(" [0-9]+", instruction)]
# this is for part 2
a.append(sides[0])
b.append(sides[1])
c.append(sides[2])
# solve part 1
sides.sort()
if sides[0] + sides[1] > sides[2]:
valid_1 += 1
print(valid_1)
for i in range(0, len(a), 3):
# row a
sides = a[i:i+3]
sides.sort()
if sides[0] + sides[1] > sides[2]:
valid_2 += 1
# row b
sides = b[i:i+3]
sides.sort()
if sides[0] + sides[1] > sides[2]:
valid_2 += 1
# row c
sides = c[i:i+3]
sides.sort()
if sides[0] + sides[1] > sides[2]:
valid_2 += 1
print(valid_2)