We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 831dd55 commit 2bfdceaCopy full SHA for 2bfdcea
puzzles/solutions/2023/d03/schematic_parser.py
@@ -94,3 +94,16 @@ def _is_number_adjacent(
94
abs(row - position_row) <= 1 and abs(column - position_column) <= 1
95
for row, column in digits_positions
96
)
97
+
98
+ def calculate_gear_ratios_sum(self):
99
+ gear_ratios_sum = 0
100
+ for gear_position in self._gears_positions:
101
+ adjacent_numbers = [
102
+ number
103
+ for number, digits_positions in self._numbers
104
+ if self._is_number_adjacent(gear_position, digits_positions)
105
+ ]
106
+ if len(adjacent_numbers) == 2:
107
+ gear_ratio = adjacent_numbers[0] * adjacent_numbers[1]
108
+ gear_ratios_sum += gear_ratio
109
+ return gear_ratios_sum
0 commit comments