package
0.0.0-20241212132503-87920a24b687
Repository: https://github.com/shraddhaag/aoc.git
Documentation: pkg.go.dev

# README

Day 10 solution

Part 2 was tough!

I did a set of things here that finally led me to the answer:

  1. Replaced the hard to visualise |, -, F, 7, J and L with unicode characters , , , , , .
Inputtest3.txttest4.txttest5.txt
Output3a4a5a
  1. Replace S with the correct pipe replacement.
Inputtest3.txttest4.txttest5.txt
Output3a4a5a
  1. Clean the above by removing the characters from the side ie, replace all characters with a whitespace in each line before the first character from pipe path is encountered.
Inputtest3.txttest4.txttest5.txt
Output3a4a5a
  1. Now that we have an input we can work with, we will count the number of characters inside the pipe path using Ray Cast Algorithm. We are doing this by evaluating the 2D matrix line by line:
    1. Keep track of number of encountered. If this count is odd, the character encountered is inside the path pipe.
    2. We can ignore any encountered.
    3. We can mostly (see next point) ignore all other pipe path characters ie , , , .
    4. We need to increment the counter by one when either ( followed by ) or ( followed by ) is encountered, as these are equivalent to a single . Note, the characters can have any number of between them and they would still be counted as a single .
Inputtest3.txttest4.txttest5.txt
Output3a4a5a

Doing the above steps for the input:

After Step 1After Step 2After Step 3After Step 4
3a3a4a5a