Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Hi,
- Very cool article.
- Its important to note that you have 101 terms there:
- [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, 1, 46, 0, 6, 23]
- The provided code is indented incorrectly and uses and obscure python feature of a for else.
- Here is the "correct" code:
- """
- def example(terms: int):
- A181391 = [0, 0]
- for n in range(1, terms):
- for m in range(n-1, -1, -1):
- if A181391[m] == A181391[n]:
- A181391.append(n-m)
- break
- else:
- A181391.append(0)
- return A181391
- # also here is some "easier" to understand code:
- def van_eck(n: int) -> list[int]:
- if n < 1:
- return []
- seq = [0]
- seen = {}
- for i in range(n - 1):
- cur = seq[i]
- if cur in seen:
- next = i - seen[cur]
- seen[cur] = i
- seq.append(next)
- else:
- seq.append(0)
- seen[cur] = i
- return seq
- # Thank you for the article
Advertisement
Add Comment
Please, Sign In to add comment