Created
September 10, 2017 17:12
-
-
Save arkenidar/abe00808bc807a673271280a201452ac to your computer and use it in GitHub Desktop.
Testing an algorithm (I don't know its name).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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