Fast Topswops calculation
JavaScript

 

function(d){for(t=0;x=(n=d[0])-1;t++)for(i=0;i&lt;n/2;i++){m=d[x-i];d[x-i]=d[i];d[i]=m}return t}


You pass it the deck, like so:

f([3, 2, 1]) // 1
f([2, 3, 1]) // 2
f([1, 2, 3]) // 0