Java (JDK), 59 bytes
a->{int c=0;for(;a[(1<<c)%(a.length-1|1)]>2;)c++;return c;}
Works reliably only for arrays with a size less than 31 or solutions with less than 31 iterations. For a more general solution, see the following solution with 63 bytes:
a->{int i=1,c=0;for(;a[i]>2;c++)i=i*2%(a.length-1|1);return c;}
Explanation
In a riffle, the next position is the previous one times two modulo either length if it's odd or length - 1 if it's even.
So I'm iterating over all indices using this formula until I find the value 2 in the array.
Credits
- -8 bytes thanks to Kevin Cruijssen. (Previous formulaalgorithm, using array)
- -5 bytes thanks to Arnauld.
Java (JDK), 59 bytes
a->{int c=0;for(;a[(1<<c)%(a.length-1|1)]>2;)c++;return c;}
Works reliably only for arrays with a size less than 31 or solutions with less than 31 iterations. For a more general solution, see the following solution with 63 bytes:
a->{int i=1,c=0;for(;a[i]>2;c++)i=i*2%(a.length-1|1);return c;}
Explanation
In a riffle, the next position is the previous one times two modulo either length if it's odd or length - 1 if it's even.
So I'm iterating over all indices using this formula until I find the value 2 in the array.
Credits
- -8 bytes thanks to Kevin Cruijssen. (Previous formula, using array)
- -5 bytes thanks to Arnauld.
Java (JDK), 59 bytes
a->{int c=0;for(;a[(1<<c)%(a.length-1|1)]>2;)c++;return c;}
Works reliably only for arrays with a size less than 31 or solutions with less than 31 iterations. For a more general solution, see the following solution with 63 bytes:
a->{int i=1,c=0;for(;a[i]>2;c++)i=i*2%(a.length-1|1);return c;}
Explanation
In a riffle, the next position is the previous one times two modulo either length if it's odd or length - 1 if it's even.
So I'm iterating over all indices using this formula until I find the value 2 in the array.
Credits
- -8 bytes thanks to Kevin Cruijssen. (Previous algorithm, using array)
- -5 bytes thanks to Arnauld.
Java (JDK), 6359 bytes
a->{int c=0;for(;a[(1<<c)%(a.length-1|1)]>2;)c++;return c;}
Works reliably only for arrays with a size less than 31 or solutions with less than 31 iterations. For a more general solution, see the following solution with 63 bytes:
a->{int i=1,c=0;for(;a[i]>2;c++)i=i*2%(a.length-1|1);return c;}
Explanation
In a riffle, the next position is the previous one times two modulo either length if it's odd or length - 1 if it's even.
So I'm iterating over all indices using this formula until I find the value 2 in the array.
Credits
- -8 bytes thanks to Kevin Cruijssen. (Previous formula, using array)
- -5 bytes thanks to Arnauld.
Java (JDK), 63 bytes
a->{int i=1,c=0;for(;a[i]>2;c++)i=i*2%(a.length-1|1);return c;}
Explanation
In a riffle, the next position is the previous one times two modulo either length if it's odd or length - 1 if it's even.
So I'm iterating over all indices using this formula until I find the value 2 in the array.
Credits
- -8 bytes thanks to Kevin Cruijssen. (Previous formula, using array)
- -5 bytes thanks to Arnauld.
Java (JDK), 59 bytes
a->{int c=0;for(;a[(1<<c)%(a.length-1|1)]>2;)c++;return c;}
Works reliably only for arrays with a size less than 31 or solutions with less than 31 iterations. For a more general solution, see the following solution with 63 bytes:
a->{int i=1,c=0;for(;a[i]>2;c++)i=i*2%(a.length-1|1);return c;}
Explanation
In a riffle, the next position is the previous one times two modulo either length if it's odd or length - 1 if it's even.
So I'm iterating over all indices using this formula until I find the value 2 in the array.
Credits
- -8 bytes thanks to Kevin Cruijssen. (Previous formula, using array)
- -5 bytes thanks to Arnauld.
Java (JDK), 6463 bytes
a->{int i=1,c=0;for(;a[i]!=2;c++;a[i]>2;c++)i=i*2%(a.length-1|1);return c;}
Explanation
In a riffle, the next position is the previous one times two modulo either length if it's odd or length - 1 if it's even.
So I'm iterating over all indices using this formula until I find the value 2 in the array.
Credits
- -8 bytes thanks to Kevin Cruijssen. (Previous formula, using array)
- -5 bytes thanks to Arnauld.
Java (JDK), 64 bytes
a->{int i=1,c=0;for(;a[i]!=2;c++)i=i*2%(a.length-1|1);return c;}
Explanation
In a riffle, the next position is the previous one times two modulo either length if it's odd or length - 1 if it's even.
So I'm iterating over all indices using this formula until I find the value 2 in the array.
Credits
- -8 bytes thanks to Kevin Cruijssen. (Previous formula, using array)
- -5 bytes thanks to Arnauld.
Java (JDK), 63 bytes
a->{int i=1,c=0;for(;a[i]>2;c++)i=i*2%(a.length-1|1);return c;}
Explanation
In a riffle, the next position is the previous one times two modulo either length if it's odd or length - 1 if it's even.
So I'm iterating over all indices using this formula until I find the value 2 in the array.
Credits
- -8 bytes thanks to Kevin Cruijssen. (Previous formula, using array)
- -5 bytes thanks to Arnauld.