Day 5

We've got a sequence of movements that we need to execute. Each number represents a forward or backward movement of that many units. After moving, the location you started at is incremented by one.

In [1]:
import pandas as pd
import numpy as np

seq = pd.read_csv("H:/python_jiggering/logs/aoc_2017/d5_input.txt", header = None)
seq = np.array(seq[0])
seq_len = len(seq)

start_loc = 0
loc = 0
next_loc = start_loc + seq[start_loc]
moves = 0

while next_loc >= 0 and next_loc <= (seq_len -1):
    moves += 1
    seq[loc] += 1
    loc = next_loc
    next_loc = loc + seq[loc]
moves + 1
Out[1]:
326618

Part 2

Part 2 seems pretty simple, they just want us to change the rules to if the offset is 3 or more, decrease by 1:

In [2]:
seq = pd.read_csv("H:/python_jiggering/logs/aoc_2017/d5_input.txt", header = None)
seq = np.array(seq[0])
seq_len = len(seq)

loc = 0
next_loc = start_loc + seq[start_loc]
moves = 0

while next_loc >= 0 and next_loc <= (seq_len -1):
    moves += 1
    seq[loc] += (-1) ** (seq[loc] >= 3)
    loc = next_loc
    next_loc = loc + seq[loc]
moves + 1
Out[2]:
21841249