Skip to content

Instantly share code, notes, and snippets.

@DeastinY
Last active June 23, 2017 13:51
Show Gist options
  • Save DeastinY/41db15ca9c2734a087f0c4ad327151c4 to your computer and use it in GitHub Desktop.
Save DeastinY/41db15ca9c2734a087f0c4ad327151c4 to your computer and use it in GitHub Desktop.
def f(a, r):
last = a[0]
for i in range(len(a)):
if abs(last - a[i]) > r:
return False
last = a[i]
return True
def g(a, r):
last, j, p = a[0], 0, []
m = len(a) - 1
while j < m:
while j < m and abs(last-a[j]) <= r:
j+=1
j-=1
p.append(a[j])
last = a[j]
while j < m and abs(last-a[j]) <= r:
j+=1
last=a[j]
return p
t = [0,1,2,3,6,7,9,11,14,15]
print(f(t,r=3))
print(g(t,r=3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment