Pass The ⚽️ Around The Circle The ball game is a game in which a number of players sit together in a circle. Each player is first assigned a number \$ n \$, either 1, 2, or 3. The game begins with any starting player, and proceeds clockwise around the circle. The current player with the ball throws it to the next player. Who the next player is solely depends on the number \$ n \$ the current player was assigned.

If \$ n = 1 \$, the next player will be the one sat directly adjacent (one space away), traveling in the current direction.

If \$ n = 2 \$, the next player will be the one sat two spaces away, traveling in the current direction.

If \$ n = 3 \$, the direction of play is first switched (clockwise to counter-clockwise, and vice-versa). The next player will then be the one sat directly adjacent, traveling in the new direction.

Task

You are given a list of numbers \$ l \$ all in the range \$ [1 - 3] \$, denoting the numbers each player was assigned. The elements in \$ l \$ are given in clockwise order, and such that the last element of \$ l \$ is adjacent to the first element. Your task is to determine the number of players who have touched the ball, before it reaches a player who previously already touched the ball.

Example

The starting player is at the first index. X represents a visited index, O represents an index visited twice.

[1, 2, 1, 1, 2, 2, 3] -&gt;
[X, 2, 1, 1, 2, 2, 3] -&gt;
[X, X, 1, 1, 2, 2, 3] -&gt;
[X, X, 1, X, 2, 2, 3] -&gt;
[X, X, 1, X, X, 2, 3] -&gt;
[X, X, 1, X, X, 2, X] -&gt;
[X, X, 1, X, X, X, X] -&gt;
[X, X, 1, O, X, X, X]
The answer is 6.


Clarifications


\$ l \$ can be inputted in any reasonable format, but the numbers 1, 2, and 3 must not change
The starting player does not have to be at the first index, but please specify where it would start
This is code-golf, so the shortest code in bytes wins!


Test Cases

Input (start is index 0) -&gt; Output
[1] -&gt; 1
[2] -&gt; 1
[3] -&gt; 1
[3, 2] -&gt; 2
[2, 1] -&gt; 1
[2, 2, 3] -&gt; 3
[1, 1, 1, 1, 1] -&gt; 5
[2, 2, 2, 2, 2] -&gt; 5
[3, 3, 3, 3, 3] -&gt; 2
[1, 3, 2, 1, 2, 3] -&gt; 2
[1, 2, 1, 1, 2, 2, 3] -&gt; 6
Python 3, 67 55 bytes



f=lambda x,*l:x and-~f(*l[x%3-1::1-x//3*2],0,*l[x%2:1])


Try it online!

Use @Leo's idea of keeping the current player at a fixed index and transforming the list instead. Be sure to check out and upvote his answer!

If the current list is [x, a, b, c, d], where x is the move of the current player, then we want to rotate the list appropriately, and replace x with 0:


If x == 1, the new list is [a, b, c, d, 0]
If x == 2, the new list is [b, c, d, 0, a]
If x == 3, the new list is [d, c, b, a, 0]
If x == 0, this player has already been visited, thus we stop the algorithm.




Python 2, 90 85 bytes



f=lambda l,d=1,p=0,*t:(p in t)^1and-~f(l,[d,-d][l[p]&gt;2],(-~l[p]%4*d-d+p)%len(l),p,*t)


Try it online!

Not every elegant, but does the job.

This recursive function keeps track of the current direction d, the position p, and the list of seen position t.