This year, I’m posting my solutions to the puzzles in the Advent of Code. Each post will consist of pseudocode, with a link to the actual code I used to solve the puzzle on Github.

And now, on with the solution:

### Day 1, part 1

Simplified problem: Following a set of instructions in the format *x0* where *x* is a direction (*L* or *R*) and *0* is the number of blocks to move, how far away from your start point are you when you arrive at your destination?

- You always start at block 0,0 and face North.

#### Solution

- Read all instructions and process into correct format
- Set
*PositionX=0* - Set
*PositionY=0* - For each instruction, turn in the specified direction and travel the required number of blocks:
- If travelling North, increase
*PositionY*by*blocks* - If travelling East, increase
*PositionX*by*blocks* - If travelling South, descrease
*PositionY*by*blocks* - If travelling West, decrease
*PositionX*by*blocks*

- If travelling North, increase
- Return the sum of the
*Absolute Value*of both*PositionX*and*PositionY*. (X and Y coordinates can be negative values. sing the absolute values will return the positive value of these number).

### Day 1, part 2

Using the same instructions, what is the first point at which you cross your path?

#### Solution

- Read all instructions and process into correct format
- Set
*PositionX=0* - Set
*PositionY=0* - Set
*ListOfCoordinates=new List(of Coordinates)* - Set
*FirstPointCrossed=nothing* - For each instruction, turn in the specified direction and travel the required number of blocks:
- Set
*i=0* - While
*i<blocks*- If travelling North, increase
*PositionY*by 1 - If travelling East, increase
*PositionX*by 1 - If travelling South, descrease
*PositionY*by 1 - If travelling West, decrease
*PositionX*by 1 - Set
*CurrentCoordinates=PositionX,PositionY* - If
*ListOfCoordinates*contains the*CurrentCoordinates***and***FirstPointCrossed=nothing*- Set
*FirstPointCrossed=CurrentCoordinates*

- Set
- End if
- Add current coordinates (
*PositionX, PositionY*) to*ListOfCoordinates* - Add 1 to
*i*

- If travelling North, increase
- End While

- Set
- Return the value of
*FirstPointCrossed*

Note: the code above will continue to travel the full path, even after we find the first point crossed. After setting *FirstPointCrossed*, we should exit the While loop and return the value.

You can find the full solution on GitHub