Skip to content

Instantly share code, notes, and snippets.

@JulienPalard
Created June 16, 2019 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JulienPalard/0342d5c1fefb19b204b789d6ee391f03 to your computer and use it in GitHub Desktop.
Save JulienPalard/0342d5c1fefb19b204b789d6ee391f03 to your computer and use it in GitHub Desktop.
def van_eck():
"""https://oeis.org/A181391
"""
seen = {}
yield 0
previous, current = 0, None
i = 1
while True:
if previous in seen:
current = i - seen[previous] - 1
else:
current = 0
yield current
seen[previous] = i - 1
previous = current
i += 1
def test_van_eck():
from_oeis = (
"0 0 1 0 2 0 2 2 1 6 0 5 0 2 6 5 4 0 5 3 0 3 2 9 0 4 9 3 6 14 0 6 3 5 "
"15 0 5 3 5 2 17 0 6 11 0 3 8 0 3 3 1 42 0 5 15 20 0 4 32 0 3 11 18 0 "
"4 7 0 3 7 3 2 31 0 6 31 3 6 3 2 8 33 0 9 56 0 3 8 7 19 0 5 37 0 3 8 8"
)
from_oeis = [int(i) for i in from_oeis.split()]
for oeis, mine in zip(from_oeis, van_eck()):
assert oeis == mine
if __name__ == "__main__":
for i in van_eck():
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment