10710
Posted: Thu Nov 04, 2004 2:47 am
My evidently pathetic algorithm that takes about 5 seconds on certain cases is as follows :
Let the input number be N
1) If N is odd , N=N+1
2) Set x = 2 and counter=1
While(x!=1)
{
x = (x<<1)%(n-1)
counter++
}
This is based on the observation that if you label the cards from 0 to n-1, then every card moves from k to (2*k)mod(n-1)
Firstly, is my observation correct that the number of shuffles required is equal to the number of shuffles it takes for card number 2 (having index 1 in using the labelling system I described) to return to index 1.
And if yes, since my algorithm is too slow, any hints are more than welcome!
[/code]
Let the input number be N
1) If N is odd , N=N+1
2) Set x = 2 and counter=1
While(x!=1)
{
x = (x<<1)%(n-1)
counter++
}
This is based on the observation that if you label the cards from 0 to n-1, then every card moves from k to (2*k)mod(n-1)
Firstly, is my observation correct that the number of shuffles required is equal to the number of shuffles it takes for card number 2 (having index 1 in using the labelling system I described) to return to index 1.
And if yes, since my algorithm is too slow, any hints are more than welcome!
[/code]