Skip to content
Froxcey edited this page Dec 4, 2023 · 2 revisions

Difficulty is all over the place

As simple as this challenge sounds, it is undoubtedly very challenging. When considering a more higher-level way of representing everything, we came up with the idea of splitting our implementation into two parts: creating an abstract representation of the schematic and identifying valid part numbers. For the abstraction, we aim to achieve the following:

  • The schematic as a 2D array (for easy indexing)
  • A list of part numbers and their respective locations

Once everything is abstracted in step 1, we can proceed to validate part numbers. For each potential part number, we use its location and length to create an area to scan for a part symbol, like this:

πŸ”πŸ”πŸ”πŸ”πŸ”
πŸ”4️⃣2️⃣0οΈβƒ£πŸ”
πŸ”πŸ”πŸ”πŸ”πŸ”

If there is a part symbol in the πŸ” area, then the part number is valid and can be added to the list of results. You can view our example implementation in zig.

Now that we have the answer to part 1, we can use the existing code to solve part 2. When searching the area, we are now looking for a gear symbol and its position. When one is found, the gear's location is stored in a HashMap. Any two numbers with duplicate gear positions are valid gear numbers, and the result can be found. You can see our example implementation in zig.

Clone this wiki locally