test for empiric cycle count in cycles with length k on Sm and l on Sn

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import numpy as np
def shuffle_right(shuffle):
x = shuffle.copy()
x[1] = [shuffle[1][(i-1)%len(shuffle[1])] for i in xrange(len(shuffle[1]))]
return x
def shuffle_equality(sh1, sh2):
for i in xrange(sh1.shape[1]):
if sh1[1][i] != sh2[1][i]:
return False
return True
def test_shuffle(m, n):
delta = m % n
divider = (m - m % n)/n
identity_shuffle = np.zeros([2, m])
for i in xrange(m):
identity_shuffle[0][i] = i
identity_shuffle[1][i] = i % n
#print identity_shuffle[1]
counter = 1
current = shuffle_right(identity_shuffle)
while (shuffle_equality(identity_shuffle, current) == False):
#print current[1]
counter += 1
current = shuffle_right(current)
return counter
def empiric_count(m, n):
if m % n == 0: return n
return m
def test_division(s):
for m in xrange(2, s):
for n in xrange(1, m):
emp = empiric_count(m, n)
real = test_shuffle(m, n)
print(m, n, '--->>>', ' emp: ' , emp, ":: real: ", real, '{{{ ', emp == real)
if (emp != real):
print 'WRONG EMPIRIC COUNT!'
return 0
s = int(input())
test_division(s)