Skip to content

Instantly share code, notes, and snippets.

@ticky
Last active October 12, 2015 20:47
Show Gist options
  • Save ticky/4085093 to your computer and use it in GitHub Desktop.
Save ticky/4085093 to your computer and use it in GitHub Desktop.
Detect if a set of numbers is complete and consecutive
#!/bin/env python
# coding: utf-8
items = [
[1, 2, 3, 5, 6, 7, 7, 8, 9, 10,11,12], # false
[2, 3, 4, 5, 6, 7, 8, 9, 10,11,12], # false
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], # true
[1, 2, 2, 4, 5, 6, 7] , # false
[1, 2, 3, 4, 5, 7] , # false
[3, 5, 1, 2, 4] # true
]
def isComplete(numberSet):
numberSet.sort()
length = len(numberSet)
expected = range(1, numberSet[-1]+1)
if(length != numberSet[-1]):
return False
return (expected == numberSet)
for nums in items:
print(isComplete(nums))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment