-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantonov_saleev.py
executable file
·32 lines (28 loc) · 1.03 KB
/
antonov_saleev.py
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
import math
from number import *
class AntonovSaleevIterator:
def __init__(self, directionNumbers, seqLength):
self.curNum = TransposedBinNumber()
self.curIndex = 0
self.seqLength = seqLength
self.directNums = [ TransposedBinNumber(Number(x,2,True)._num) \
for x in directionNumbers]
self.lenNum = int(math.log(seqLength,2))+1
self.switchingSeq = self.switchingSequence(self.lenNum)
def switchingSequence(self, q):
if q == 1:
return [1]
else:
res = list(self.switchingSequence(q-1))
res.append(q)
res.extend(self.switchingSequence(q-1))
return res
def __iter__(self):
return self
def next(self):
if self.curIndex == self.seqLength:
raise StopIteration
i = self.switchingSeq[self.curIndex]
self.curIndex += 1
self.curNum = self.curNum ^ self.directNums[i-1]
return self.curNum.toNumber()