Created
September 9, 2012 20:08
-
-
Save lstejskal/3686934 to your computer and use it in GitHub Desktop.
Detecting sequence in array
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
# 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