Skip to content

Commit c04ff30

Browse files
committed
Day 03: Solution of part 2
1 parent 72335c3 commit c04ff30

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

03/log.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ In your puzzle input, how many of the listed triangles are possible?
1212

1313
Your puzzle answer was 1050.
1414

15-
The first half of this puzzle is complete! It provides one gold star: *
16-
1715
--- Part Two ---
1816

1917
Now that you've helpfully marked up their design documents, it occurs to you that triangles are specified in groups of three vertically. Each set of three numbers in a column specifies a triangle. Rows are unrelated.
@@ -26,4 +24,8 @@ For example, given the following specification, numbers with the same hundreds d
2624
201 401 601
2725
202 402 602
2826
203 403 603
29-
In your puzzle input, and instead reading by columns, how many of the listed triangles are possible?
27+
In your puzzle input, and instead reading by columns, how many of the listed triangles are possible?
28+
29+
Your puzzle answer was 1921.
30+
31+
Both parts of this puzzle are complete! They provide two gold stars: **

03/solution.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ def __init__(self, nr):
88
super().__init__(nr)
99
self.triangle_1 = Triangle()
1010
self.possible_1 = 0
11+
self.triangles_2 = [Triangle(), Triangle(), Triangle()]
12+
self.possible_2 = 0
1113

1214
def calculate(self, test=False):
1315
self.read_instructions()
@@ -17,9 +19,18 @@ def read_instructions(self):
1719
self.read_input(True)
1820

1921
def check_triangles(self):
22+
group_part = 0
2023
for triangle in self.input:
2124
sides = re.split(r'\s+', triangle.strip(' '))
2225
self.triangle_1.set_sides(sides)
2326
if self.triangle_1.is_possible():
2427
self.possible_1 += 1
28+
for nr in range(0, 3):
29+
self.triangles_2[nr].set_side(group_part, sides[nr])
30+
if group_part == 2:
31+
for nr in range(0, 3):
32+
if self.triangles_2[nr].is_possible():
33+
self.possible_2 += 1
34+
group_part = (group_part + 1) % 3
2535
self.set_solution(1, self.possible_1)
36+
self.set_solution(2, self.possible_2)

0 commit comments

Comments
 (0)