The position of the scanner at given depth is given as a function of time t and the amplitude m (which is the scanner's range minus 1).
Because it moves back and forth its position is given by triangular wave equation x = m - abs(i % (2*m) - m)
https://stackoverflow.com/questions/1073606/is-there-a-one-line-function-that-generates-a-triangle-wavescanner position S = m - abs(x % (2*m) - m)
because x = t (we move one per second)
S = m - abs(t % (2*m) - m)
So we are caught when that is equal to zero.
For part 2, t is simply (t+delay) , and increment delay till you find one where you are never caught (the equation above is equal to zero).
I originally did it with a linq statement that was evaluating all the positions even if it were caught, once I changed it to one that moves onto the next as soon as it's caught that brings it from 11 seconds to under a second.
Time to run should be proportional to the number of positions with a scanner, regardless of the max depth of any position with a scanner.
https://github.com/bjtaylor1/AoC2017/blob/day13part2/Day13/Program.cs