Skip to content

Instantly share code, notes, and snippets.

@managedkaos
Created August 1, 2017 18:52
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 managedkaos/cf76cd5d4c33689f47779adaee2cb42f to your computer and use it in GitHub Desktop.
Save managedkaos/cf76cd5d4c33689f47779adaee2cb42f to your computer and use it in GitHub Desktop.
Given an array of ints, return True if the sequence of numbers 1, 2, 3 appears in the array somewhere. array123([1, 1, 2, 3, 1]) → True array123([1, 1, 2, 4, 1]) → False array123([1, 1, 2, 1, 2, 3]) → True
tests = {"1":[1,1,2,3,1],"2":[1,1,2,4,1],"3":[1,1,2,1,2,3]}
def array123(array):
if len(array) < 3:
return False
for (index, item) in enumerate(array):
if item == 1:
state1 = True
elif (item == 2) and state1:
state2 = True
elif (item == 3) and state2:
return True
else:
state1 = False
state2 = False
if index == len(array) - 1:
return False
for test in tests:
print "starting test %s" % test
print array123(tests[test])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment