Day 13

We have a puzzle where we are moving through different layers. Each layer has a number of locations the surveyor can be in. The 'storyline' says that we are caught if the surveyor is in the first position when the person enters that layer. This looks like just a very fancy modular arithmetic problem to me:

In [1]:
initial = open('/Users/Sven/py_files/aoc_2017/d13_input.txt').readlines()
initial[:5]
Out[1]:
['0: 3\n', '1: 2\n', '2: 6\n', '4: 4\n', '6: 4\n']
In [2]:
layers = [int(x.split(':')[0]) for x in initial]
depths = [int(x.split(': ')[1].replace('\n', '')) for x in initial]
print(layers[:5])
print(depths [:5])
[0, 1, 2, 4, 6]
[3, 2, 6, 4, 4]

So I think this will be easier to think about moving in a circle than moving down then up so let's just take one less than twice all the depths:

In [3]:
depths2 = [2*(x-1) for x in depths]

Are these getting easier? I feel like this one is very simple...

In [4]:
checks = [int((lay % dep) == 0) for lay, dep in zip(layers,depths2)]
total = [dep*lay*chk for lay, dep, chk in zip(layers,depths, checks)]
sum(total)
Out[4]:
632

Part 2

So now we basically want to figure out what the smallest amount of delay time we can wait before starting that will cause none of the sensors to go off. Note that this is different than saying we need the sum to be zero because being caught at the zero-th level does not count towards the total but does count as being caught.

Looks easy enough, just while to we get a flawless escape:

In [ ]:
delay = 0
complete = 1
while complete != 0:
    delay +=1
    checks = [int((lay + delay) % dep == 0) for lay, dep in zip(layers,depths2)]
    complete = sum(checks)
delay