Skip to content

Instantly share code, notes, and snippets.

@AdoHaha
Created November 19, 2021 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdoHaha/144264cab487fe1a988ab762d6d9f4f2 to your computer and use it in GitHub Desktop.
Save AdoHaha/144264cab487fe1a988ab762d6d9f4f2 to your computer and use it in GitHub Desktop.
class Shifting:
"""minimalistic shifting register"""
point = 0
def __init__(self,el,how_m):
"""el -- first element to add
how_m -- length of shifting register
"""
self.lis = [el for ii in range(how_m)] # we start with multiplying first element
self.how_m = how_m
def give_elements(self):
nn = 0
for el in self.lis[self.point:]:
if nn<self.how_m:
yield el
else:
break
nn+=1
for el in self.lis[0:self.point]:
if nn<self.how_m:
yield el
else:
break
nn+=1
def add_element(self,el):
self.lis[self.point] = el
self.point +=1
self.point = self.point %self.how_m
#usage
#shif = Shifting(1,21)
#for el in range(21):
# shif.add_element(el)
#print(list(shif.give_elements()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment