2-1 | Bathroom Security

You arrive at Easter Bunny Headquarters under cover of darkness. However, you left in such a rush that you forgot to use the bathroom! Fancy office buildings like this one usually have keypad locks on their bathrooms, so you search the front desk for the code.

"In order to improve security," the document you find says, "bathroom codes will no longer be written down. Instead, please memorize and follow the procedure below to access the bathrooms."

The document goes on to explain that each button to be pressed can be found by starting on the previous button and moving to adjacent buttons on the keypad: U moves up, D moves down, L moves left, and R moves right. Each line of instructions corresponds to one button, starting at the previous button (or, for the first line, the "5" button); press whatever button you're on at the end of each line. If a move doesn't lead to a button, ignore it.

You can't hold it much longer, so you decide to figure out the code as you walk to the bathroom. You picture a keypad like this:


Suppose your instructions are:


So, in this example, the bathroom code is 1985.

Your puzzle input is the instructions from the document you found at the front desk. What is the bathroom code?

Assume X is the row, and Y is the column. X starts at 0 and Y starts at 1. Results are calculated by (X*3)+Y. Example - Field 8 - Row 3, Col 2 => (2,2)

The resulting Keypad code is

All the tasks have been provided by adventofcode.com. I only copied the task descriptions over to allow re-capping later, in case the tasks get lost.

My horrible code can be looked at on GitHub