solve Day03 in rust
This commit is contained in:
@@ -58,3 +58,10 @@ Consider the same engine schematic again:
|
||||
In this schematic, there are two gears. The first is in the top left; it has part numbers 467 and 35, so its gear ratio is 16345. The second gear is in the lower right; its gear ratio is 451490. (The * adjacent to 617 is not a gear because it is only adjacent to one part number.) Adding up all of the gear ratios produces 467835.
|
||||
|
||||
What is the sum of all of the gear ratios in your engine schematic?
|
||||
|
||||
|
||||
## Solution Algorithm
|
||||
1. **Read the Schematic**: Read the engine schematic from a file into a grid format for processing.
|
||||
2. **Identify Part Numbers**: For each character in the grid, check if it's adjacent to a symbol (other than .). If so, extract the full number starting from that digit (ensuring left-to-right reading).
|
||||
3. **Find Gears and Calculate Ratios**: Iterate through the grid and identify * symbols. For each *, find all adjacent part numbers. If exactly two part numbers are found, calculate the gear ratio by multiplying these two numbers.
|
||||
3. **Sum Gear Ratios**: Add up all the calculated gear ratios to get the total sum.
|
||||
|
||||
Reference in New Issue
Block a user