From bb24354cb5db1a18224bddbdaa12db581114c2d0 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 22 Apr 2019 13:29:50 +0100 Subject: [PATCH] simplify further,use max() on elements remove function, use elements=[0] to accumulate exponents --- TLB/src/LFSR2.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/TLB/src/LFSR2.py b/TLB/src/LFSR2.py index 4baf2055..1bddc1a8 100644 --- a/TLB/src/LFSR2.py +++ b/TLB/src/LFSR2.py @@ -8,22 +8,18 @@ class LFSRPolynomial(set): """ implements a polynomial for use in LFSR """ def __init__(self, exponents=()): - max_exponent = 0 - - def elements(): - nonlocal max_exponent - yield 0 # 0 is always required - for e in exponents: - if not isinstance(e, int): - raise TypeError("exponent %s must be an integer" % repr(e)) - if e < 0: - raise ValueError("exponent %d must not be negative" % e) - if e > max_exponent: - max_exponent = e - if e != 0: # skip zeros - yield e - set.__init__(self, elements()) - self.max_exponent = max_exponent + self.max_exponent = 0 + elements = [0] # 0 is always required + for e in exponents: + if not isinstance(e, int): + raise TypeError("exponent %s must be an integer" % repr(e)) + if e < 0: + raise ValueError("exponent %d must not be negative" % e) + self.max_exponent = max(e, self.max_exponent) + if e != 0: # skip any zeros + elements.append(e) + + set.__init__(self, elements) @property def exponents(self): -- 2.30.2