Scarecrow Robot

Scarecrow Robot

A farmer employs a scarecrow robot to protect his cornfield. The robot follows a path around the plantation, passing through stations circled. Each day, the robot starts at station 1 and follows a series of commands that move it to neighboring stations, both clockwise (1) and counterclockwise (-1).

example

Given also a number of control station, which is under monitoring, calculate how many times the robot visits the station during a day.

Input: Two integers (int) and a list (list) of integers.

Output: Integer.

Examples:

assert visits(8, 3, [1, -1, 1, 1, 1, -1, 1, 1]) == 2
assert visits(5, 1, [1, 1, 1, 1]) == 1
assert visits(2, 1, [1]) == 1
assert visits(4, 4, [-1, 1, 1, 1]) == 1