Skip to content

Instantly share code, notes, and snippets.

@anacrolix
Created June 2, 2015 12:46
Show Gist options
  • Save anacrolix/5274c5205c6c65218805 to your computer and use it in GitHub Desktop.
Save anacrolix/5274c5205c6c65218805 to your computer and use it in GitHub Desktop.
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