Created
September 6, 2013 22:39
-
-
Save DeaconDesperado/6470955 to your computer and use it in GitHub Desktop.
Circular Arrays
This file contains hidden or 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
cases = [ | |
([2,2,-1],True), | |
([3,1,2,-2],True), | |
([-4,2,4],False), | |
([9,8,8],False) | |
] | |
def is_circular_complete(case): | |
key = 0 | |
size = len(case) | |
for index in xrange(size): | |
nextkey = case[key] | |
if nextkey > size: | |
return False | |
key = (nextkey+key) % size | |
if key == 0: | |
return True | |
return False | |
for case,should in cases: | |
assert is_circular_complete(case) == should |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment