#JavaScript (ES6), 44 bytes
JavaScript (ES6), 44 bytes
Shorter version suggested by @nwellnhof
Expects a deck with 1-indexed cards as input.
f=(a,x=1)=>a[x]-2&&1+f(a,x*2%(a.length-1|1))
Given a deck \$[c_0,\ldots,c_{L-1}]\$ of length \$L\$, we define:
$$x_n=\begin{cases} 2^n\bmod L&\text{if }L\text{ is odd}\\ 2^n\bmod (L-1)&\text{if }L\text{ is even}\\ \end{cases}$$
And we look for \$n\$ such that \$c_{x_n}=2\$.
#JavaScript (ES6), (削除) 57 52 (削除ここまで) 50 bytes
JavaScript (ES6), (削除) 57 52 (削除ここまで) 50 bytes
Expects a deck with 0-indexed cards as input.
f=(a,x=1,k=a.length-1|1)=>a[1]-x%k&&1+f(a,x*-~k/2)
###How?
How?
Since JS is lacking native support for extracting array slices with a custom stepping, simulating the entire riffle-shuffle would probably be rather costly (but to be honest, I didn't even try). However, the solution can also be found by just looking at the 2nd card and the total number of cards in the deck.
Given a deck of length \$L\$, this code looks for \$n\$ such that:
$$c_2\equiv\left(\frac{k+1}{2}\right)^n\pmod k$$
where \$c_2\$ is the second card and \$k\$ is defined as:
$$k=\begin{cases} L&\text{if }L\text{ is odd}\\ L-1&\text{if }L\text{ is even}\\ \end{cases}$$
#JavaScript (ES6), 44 bytes
Shorter version suggested by @nwellnhof
Expects a deck with 1-indexed cards as input.
f=(a,x=1)=>a[x]-2&&1+f(a,x*2%(a.length-1|1))
Given a deck \$[c_0,\ldots,c_{L-1}]\$ of length \$L\$, we define:
$$x_n=\begin{cases} 2^n\bmod L&\text{if }L\text{ is odd}\\ 2^n\bmod (L-1)&\text{if }L\text{ is even}\\ \end{cases}$$
And we look for \$n\$ such that \$c_{x_n}=2\$.
#JavaScript (ES6), (削除) 57 52 (削除ここまで) 50 bytes
Expects a deck with 0-indexed cards as input.
f=(a,x=1,k=a.length-1|1)=>a[1]-x%k&&1+f(a,x*-~k/2)
###How?
Since JS is lacking native support for extracting array slices with a custom stepping, simulating the entire riffle-shuffle would probably be rather costly (but to be honest, I didn't even try). However, the solution can also be found by just looking at the 2nd card and the total number of cards in the deck.
Given a deck of length \$L\$, this code looks for \$n\$ such that:
$$c_2\equiv\left(\frac{k+1}{2}\right)^n\pmod k$$
where \$c_2\$ is the second card and \$k\$ is defined as:
$$k=\begin{cases} L&\text{if }L\text{ is odd}\\ L-1&\text{if }L\text{ is even}\\ \end{cases}$$
JavaScript (ES6), 44 bytes
Shorter version suggested by @nwellnhof
Expects a deck with 1-indexed cards as input.
f=(a,x=1)=>a[x]-2&&1+f(a,x*2%(a.length-1|1))
Given a deck \$[c_0,\ldots,c_{L-1}]\$ of length \$L\$, we define:
$$x_n=\begin{cases} 2^n\bmod L&\text{if }L\text{ is odd}\\ 2^n\bmod (L-1)&\text{if }L\text{ is even}\\ \end{cases}$$
And we look for \$n\$ such that \$c_{x_n}=2\$.
JavaScript (ES6), (削除) 57 52 (削除ここまで) 50 bytes
Expects a deck with 0-indexed cards as input.
f=(a,x=1,k=a.length-1|1)=>a[1]-x%k&&1+f(a,x*-~k/2)
How?
Since JS is lacking native support for extracting array slices with a custom stepping, simulating the entire riffle-shuffle would probably be rather costly (but to be honest, I didn't even try). However, the solution can also be found by just looking at the 2nd card and the total number of cards in the deck.
Given a deck of length \$L\$, this code looks for \$n\$ such that:
$$c_2\equiv\left(\frac{k+1}{2}\right)^n\pmod k$$
where \$c_2\$ is the second card and \$k\$ is defined as:
$$k=\begin{cases} L&\text{if }L\text{ is odd}\\ L-1&\text{if }L\text{ is even}\\ \end{cases}$$
#JavaScript (ES6), 44 bytes
Shorter version suggested by @nwellnhof
Expects a deck with 1-indexed deckcards as input.
f=(a,x=1)=>a[x]-2&&1+f(a,x*2%(a.length-1|1))
Given a deck \$[c_0,\ldots,c_{L-1}]\$ of length \$L\$, we define:
$$x_n=\begin{cases} 2^n\bmod L&\text{if }L\text{ is odd}\\ 2^n\bmod (L-1)&\text{if }L\text{ is even}\\ \end{cases}$$
And we look for \$n\$ such that \$c_{x_n}=2\$.
#JavaScript (ES6), (削除) 57 52 (削除ここまで) 50 bytes
Expects a deck with 0-indexed deckcards as input.
f=(a,x=1,k=a.length-1|1)=>a[1]-x%k&&1+f(a,x*-~k/2)
###How?
Since JS is lacking native support for extracting array slices with a custom stepping, simulating the entire riffle-shuffle would probably be rather costly (but to be honest, I didn't even try). However, the solution can also be found by just looking at the 2nd card and the total number of cards in the deck.
Given a deck of length \$L\$, this code looks for \$n\$ such that:
$$c_2\equiv\left(\frac{k+1}{2}\right)^n\pmod k$$
where \$c_2\$ is the second card and \$k\$ is defined as:
$$k=\begin{cases} L&\text{if }L\text{ is odd}\\ L-1&\text{if }L\text{ is even}\\ \end{cases}$$
#JavaScript (ES6), 44 bytes
Shorter version suggested by @nwellnhof
Expects a 1-indexed deck as input.
f=(a,x=1)=>a[x]-2&&1+f(a,x*2%(a.length-1|1))
#JavaScript (ES6), (削除) 57 52 (削除ここまで) 50 bytes
Expects a 0-indexed deck as input.
f=(a,x=1,k=a.length-1|1)=>a[1]-x%k&&1+f(a,x*-~k/2)
###How?
Since JS is lacking native support for extracting array slices with a custom stepping, simulating the entire riffle-shuffle would probably be rather costly (but to be honest, I didn't even try). However, the solution can also be found by just looking at the 2nd card and the total number of cards in the deck.
Given a deck of length \$L\$, this code looks for \$n\$ such that:
$$c_2\equiv\left(\frac{k+1}{2}\right)^n\pmod k$$
where \$c_2\$ is the second card and \$k\$ is defined as:
$$k=\begin{cases} L&\text{if }L\text{ is odd}\\ L-1&\text{if }L\text{ is even}\\ \end{cases}$$
#JavaScript (ES6), 44 bytes
Shorter version suggested by @nwellnhof
Expects a deck with 1-indexed cards as input.
f=(a,x=1)=>a[x]-2&&1+f(a,x*2%(a.length-1|1))
Given a deck \$[c_0,\ldots,c_{L-1}]\$ of length \$L\$, we define:
$$x_n=\begin{cases} 2^n\bmod L&\text{if }L\text{ is odd}\\ 2^n\bmod (L-1)&\text{if }L\text{ is even}\\ \end{cases}$$
And we look for \$n\$ such that \$c_{x_n}=2\$.
#JavaScript (ES6), (削除) 57 52 (削除ここまで) 50 bytes
Expects a deck with 0-indexed cards as input.
f=(a,x=1,k=a.length-1|1)=>a[1]-x%k&&1+f(a,x*-~k/2)
###How?
Since JS is lacking native support for extracting array slices with a custom stepping, simulating the entire riffle-shuffle would probably be rather costly (but to be honest, I didn't even try). However, the solution can also be found by just looking at the 2nd card and the total number of cards in the deck.
Given a deck of length \$L\$, this code looks for \$n\$ such that:
$$c_2\equiv\left(\frac{k+1}{2}\right)^n\pmod k$$
where \$c_2\$ is the second card and \$k\$ is defined as:
$$k=\begin{cases} L&\text{if }L\text{ is odd}\\ L-1&\text{if }L\text{ is even}\\ \end{cases}$$
#JavaScript (ES6), 44 bytes
Shorter version thanks tosuggested by @nwellnhof
Expects a 1-indexed deck as input.
f=(a,x=1)=>a[x]-1&&1+f2&&1+f(a,x*2%(a.length-1|1))
#JavaScript (ES6), (削除) 57 52 (削除ここまで) 50 bytes
Expects a 0-indexed deck as input.
f=(a,x=1,k=a.length-1|1)=>a[1]-x%k&&1+f(a,x*-~k/2)
###How?
Since JS is lacking native support for extracting array slices with a custom stepping, simulating the entire riffle-shuffle would probably be rather costly (but to be honest, I didn't even try). However, the solution can also be found by just looking at the 2nd card and the total number of cards in the deck.
Given a deck of length \$L\$, this code looks for \$n\$ such that:
$$c_2\equiv\left(\frac{k+1}{2}\right)^n\pmod k$$
where \$c_2\$ is the second card and \$k\$ is defined as:
$$k=\begin{cases} L&\text{if }L\text{ is odd}\\ L-1&\text{if }L\text{ is even}\\ \end{cases}$$
#JavaScript (ES6), 44 bytes
Shorter version thanks to @nwellnhof
f=(a,x=1)=>a[x]-1&&1+f(a,x*2%(a.length-1|1))
#JavaScript (ES6), (削除) 57 52 (削除ここまで) 50 bytes
Expects a 0-indexed deck as input.
f=(a,x=1,k=a.length-1|1)=>a[1]-x%k&&1+f(a,x*-~k/2)
###How?
Since JS is lacking native support for extracting array slices with a custom stepping, simulating the entire riffle-shuffle would probably be rather costly (but to be honest, I didn't even try). However, the solution can also be found by just looking at the 2nd card and the total number of cards in the deck.
Given a deck of length \$L\$, this code looks for \$n\$ such that:
$$c_2\equiv\left(\frac{k+1}{2}\right)^n\pmod k$$
where \$c_2\$ is the second card and \$k\$ is defined as:
$$k=\begin{cases} L&\text{if }L\text{ is odd}\\ L-1&\text{if }L\text{ is even}\\ \end{cases}$$
#JavaScript (ES6), 44 bytes
Shorter version suggested by @nwellnhof
Expects a 1-indexed deck as input.
f=(a,x=1)=>a[x]-2&&1+f(a,x*2%(a.length-1|1))
#JavaScript (ES6), (削除) 57 52 (削除ここまで) 50 bytes
Expects a 0-indexed deck as input.
f=(a,x=1,k=a.length-1|1)=>a[1]-x%k&&1+f(a,x*-~k/2)
###How?
Since JS is lacking native support for extracting array slices with a custom stepping, simulating the entire riffle-shuffle would probably be rather costly (but to be honest, I didn't even try). However, the solution can also be found by just looking at the 2nd card and the total number of cards in the deck.
Given a deck of length \$L\$, this code looks for \$n\$ such that:
$$c_2\equiv\left(\frac{k+1}{2}\right)^n\pmod k$$
where \$c_2\$ is the second card and \$k\$ is defined as:
$$k=\begin{cases} L&\text{if }L\text{ is odd}\\ L-1&\text{if }L\text{ is even}\\ \end{cases}$$