Created
June 2, 2015 12:46
-
-
Save anacrolix/5274c5205c6c65218805 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def alternates_even_odd(x): | |
x = iter(x) | |
try: | |
while True: | |
if next(x)%2: | |
return False | |
if not next(x)%2: | |
return False | |
except StopIteration: | |
return True | |
def check(expected, sequence): | |
actual = alternates_even_odd(sequence) | |
print(actual) | |
if alternates_even_odd(sequence) is not expected: | |
print('fuck', sequence) | |
check(True, [0, 1, 2, 3]) | |
check(False, [0, 1, 3, 2]) | |
check(True, []) | |
check(False, [4, 7, 5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment