Skip to content

Instantly share code, notes, and snippets.

@arkenidar
Created September 10, 2017 17:12
Show Gist options
  • Save arkenidar/abe00808bc807a673271280a201452ac to your computer and use it in GitHub Desktop.
Save arkenidar/abe00808bc807a673271280a201452ac to your computer and use it in GitHub Desktop.
Testing an algorithm (I don't know its name).
#!/usr/bin/env python3
""" Testing an algorithm (I don't know its name). """
def tests():
""" Tests. """
if [0, 0, 0, 1, 1, 1, 0, 1] == list(produced([0, 0, 0, 1, 0, 0, 1, 1])):
print('test success')
else:
print('test failure')
def produced(toggler):
""" Transformation function. """
if len(toggler) > 0:
ret = toggler[0]
yield ret
for cur in toggler[1:]:
# 0:same, 1:different
if cur == 0:
ret = ret
elif cur == 1:
ret = 1 - ret
yield ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment