Advent of Code: Day 1 Solution

It has begun!

Day one of the Advent of Code has arrived. I've decided to start this year working with Python 2.x, and may transition over to Go at some point.

My solution to Day 1 is available on Github. My code is also below.

Part One:

import re

# Read in the input file.
with open ("input.txt", "r") as myfile:  
    data=myfile.read().replace('\n', '')

# Split the data read in into a list delimited by commas.
instructions = data.split(',')

directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # Direction Vectors for North, South, East, WEst  
currentDirectionIndex = 0  
currentLocation = [0, 0]

for instruction in instructions:  
    # Change the direction based on the instruction
    if 'R' in instruction:
        currentDirectionIndex += 1
    else: currentDirectionIndex -= 1

    # Fix out of bounds issues
    if currentDirectionIndex < 0:
        currentDirectionIndex = 3
    elif currentDirectionIndex > 3:
        currentDirectionIndex = 0


    amount = re.findall(r'\d+', instruction)
    amount = int(amount[0])

    currentLocation[0] += (directions[currentDirectionIndex][0] * amount)
    currentLocation[1] += (directions[currentDirectionIndex][1] * amount)

    print abs(currentLocation[0]) + abs(currentLocation[1])

Part 2:

import re

# Read in the input file.
with open ("input.txt", "r") as myfile:  
    data=myfile.read().replace('\n', '')

# Split the data read in into a list delimited by commas.
instructions = data.split(',')

directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # Direction Vectors for North, South, East, WEst  
currentDirectionIndex = 0  
currentLocation = [0, 0]  
visitedLocations = []  
solved = False

for instruction in instructions:  
    if not solved:
        # Change the direction based on the instruction
        if 'R' in instruction:
            currentDirectionIndex += 1
        else: currentDirectionIndex -= 1

        # Fix out of bounds issues
        if currentDirectionIndex < 0:
            currentDirectionIndex = 3
        elif currentDirectionIndex > 3:
            currentDirectionIndex = 0


        amount = re.findall(r'\d+', instruction)
        amount = int(amount[0])

        for i in range(amount):
            currentLocation[0] += (directions[currentDirectionIndex][0])
            currentLocation[1] += (directions[currentDirectionIndex][1])
            if (currentLocation[0], currentLocation[1]) in visitedLocations:
                print abs(currentLocation[0]) + abs(currentLocation[1])
                solved = True
            visitedLocations.append((currentLocation[0], currentLocation[1]))

A few notes. I feel like there is probably a more efficient way of doing the direction lookup and switching. Also, I am not sure about the way the distance amount is parsed out; there has to be an easier way to parse the number than a regex, right?

Suggestions? Questions? Reach out to me on Github or Twitter

Overall I'm very excited for these new puzzles!