fork(4) download
  1.  
  2. def f(d):
  3. print('For d =', d)
  4. # ar is the current tree, 0 is the root
  5. # ar[i] is the bitset of values xor-ed together
  6. ar = [(1 << i) for i in range(d)]
  7. a0 = ar[:]
  8. p = 0
  9. while 1:
  10. p += 1
  11. for i in range(d):
  12. for j in range(i+1, d):
  13. ar[i] ^= ar[j]
  14. for i in range(d):
  15. print((ar[0]>>i) & 1, end='')
  16. print('')
  17. if ar==a0:
  18. break
  19. print('Period is', p)
  20.  
  21. f(4)
  22.  
  23. f(6)
  24.  
  25. f(8)
Success #stdin #stdout 0.01s 28384KB
stdin
Standard input is empty
stdout
For d = 4
1111
1010
1100
1000
Period is 4
For d = 6
111111
101010
110011
100010
111100
101000
110000
100000
Period is 8
For d = 8
11111111
10101010
11001100
10001000
11110000
10100000
11000000
10000000
Period is 8