Skip to content

Instantly share code, notes, and snippets.

@msalahi
Created October 21, 2011 04:34
Show Gist options
  • Save msalahi/1303103 to your computer and use it in GitHub Desktop.
Save msalahi/1303103 to your computer and use it in GitHub Desktop.
gettin' some chains
def landon(array,k,threshold):
sections=[]
start,end=0,0
for i in range(0,len(array)):
#print i,array[i],"start: ",start,"end: ",end
if array[i]<threshold:
start= start if arr[start]<threshold else i
end=i
else:
if (end-start)+1>=k: sections.append((start,end+1))
start=i
end=i
if (end-start)+1>=k: sections.append((start,end+1))
return sections
arr = [1,2,3,3,3,3,4,3,5,6,6,7,7,7,7,8,8,8,1,2,3,4,4,4,4,4,4]
print landon(arr,4,8)
print landon(arr,4,5)
print landon(arr,4,4)
print landon(arr,4,3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment