Skip to content

Instantly share code, notes, and snippets.

@lstejskal
Created September 9, 2012 20:08
Show Gist options
  • Save lstejskal/3686934 to your computer and use it in GitHub Desktop.
Save lstejskal/3686934 to your computer and use it in GitHub Desktop.
Detecting sequence in array
# How to detect sequence in an array
def is_sequence(arr):
"Return True if the array is sequence."
return (len(set(arr)) == len(arr)) and ((max(arr) - min(arr)) == (len(arr) - 1))
def test():
"Test cases for the functions in poker program."
"Test cases for the Array.sequence method."
assert is_sequence([1,2,3,4,5]) == True
assert is_sequence([5,1,2,3,4]) == True
assert is_sequence([1,2,3,3,5]) == False
return 'tests pass'
print test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment