Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
encse authored Dec 6, 2024
1 parent 38a0387 commit c6760fa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion 2024/Day06/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ Read the [full puzzle](https://adventofcode.com/2024/day/6).

This has been a straightforward implementation challenge. I wrote a `Walk` function that tracks the guard's movement and returns the visited locations. It also determines whether the guard enters a loop or exits the grid. `Part1` utilizes only the location information, while `Part2` adds blockers along the guard's path and counts the instances where he starts walking in a cycle.

I use complex numbers to keep track of the guard's position and direction. To make a 90º turn in 2D you need swap the coordinates and multiply _one_ of them by -1. The turn can be clockwise or counterclockwise, it depends on which coordinate was multiplied. Here we use complex numbers to represent coordinates, and we get the same effect by simply multiplying with ImaginaryOne or `i`. `-i` turns right, and `i` to left (but this depends on how you draw your coordinate system of course, 'i' points upwards in mine). If this sounds a bit magical to You, I suggest trying it out on a few vectors by hand.
To make a 90º turn in 2D you need swap the coordinates and multiply _one_ of them by -1. The turn can be clockwise or counterclockwise, it depends on which coordinate was multiplied.

Here we use complex numbers to represent coordinates, and we get the same effect by simply multiplying with ImaginaryOne or `i`. `-i` turns right, and `i` to left (but this depends on how you draw your coordinate system of course, 'i' points upwards in mine). If this sounds a bit magical to You, I suggest trying it out on a few vectors by hand.

0 comments on commit c6760fa

Please sign in to comment.