Skip to content

Instantly share code, notes, and snippets.

@maxdeliso
Created September 18, 2016 18:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxdeliso/fef3ad7302a35f830c00848630fdc834 to your computer and use it in GitHub Desktop.
Save maxdeliso/fef3ad7302a35f830c00848630fdc834 to your computer and use it in GitHub Desktop.
""" https://en.wikipedia.org/wiki/Golomb_sequence """
def golomb(n):
d = [1]
for i in range(0, n - 1):
next_val = d[len(d) - 1] + 1
d.append(next_val)
for j in range(0, d[next_val - 1] - 1):
d.append(next_val)
return d
@maxdeliso
Copy link
Author

>>> golomb(10)
[1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment