Skip to content

Instantly share code, notes, and snippets.

@anddam
Last active November 1, 2016 09:47
Show Gist options
  • Select an option

  • Save anddam/f7e4bebc025379168630aac557f5b62b to your computer and use it in GitHub Desktop.

Select an option

Save anddam/f7e4bebc025379168630aac557f5b62b to your computer and use it in GitHub Desktop.
# The idea is from http://i.imgur.com/iVLQKSW.jpg
def sequence(n):
value, past = 0, set()
for c in range(n):
t = value - c
value = t if (t > 0 and t not in past) else (value + c)
past.add(value)
yield (value, c, past)
# The idea is from http://i.imgur.com/iVLQKSW.jpg
def sequence(n):
value, past = 0, []
for c in range(n):
t = value - c
if t > 0 and t not in past:
value = t
else:
value += c
past.append(value)
yield (value, c, past)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment