Counting the number of page turns to arrive at some specified page
Math.min(p / 2, n / 2 - p / 2)

Explanation:


If we go from start page \$1\$ takes \$0\$; page \$2,3\$ takes \$1\$; page \$4,5\$ takes \$2\$ and so on. So for \$2k,2k+1\$ we require \$k\$ turns. Hence \$p=2k,2k+1\implies \lfloor p/2\rfloor = k\$
If we go from the back  it depends on:


If \$n\$ is odd then \$n,n-1\$ take \$0\$; \$n-2,n-3\$ takes \$1\$ and so on. So \$n-2k,n-(2k+1)\$ takes \$k\$. 

Let \$n=2q+1\$ then \$p=2q-2k+1,2q-2k\implies \lfloor p/2\rfloor = q-k\$ 

i.e. \$k=q-\lfloor p/2\rfloor=\lfloor n/2\rfloor -\lfloor p/2\rfloor \$
If \$n\$ is even then \$n\$ takes \$0\$; \$n-1,n-2\$ takes \$1\$ and so on. So \$n-(2k-1),n-2k\$ takes \$k\$.

Let \$n=2q\$ then \$p=2q-2k,2q-2k+1\implies \lfloor p/2\rfloor=q-k\$

i.e. \$k=q-\lfloor p/2\rfloor=\lfloor n/2\rfloor -\lfloor p/2\rfloor\$