Guest User

Untitled

a guest
Nov 7th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. """
  2. Hi,
  3. Very cool article.
  4. Its important to note that you have 101 terms there:
  5. [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]
  6.  
  7. The provided code is indented incorrectly and uses and obscure python feature of a for else.
  8. Here is the "correct" code:
  9. """
  10. def example(terms: int):
  11.     A181391 = [0, 0]
  12.     for n in range(1, terms):
  13.         for m in range(n-1, -1, -1):
  14.             if A181391[m] == A181391[n]:
  15.                 A181391.append(n-m)
  16.                 break
  17.         else:
  18.             A181391.append(0)
  19.     return A181391
  20.  
  21.  
  22. # also here is some "easier" to understand code:
  23. def van_eck(n: int) -> list[int]:
  24.     if n < 1:
  25.         return []
  26.     seq = [0]
  27.     seen = {}
  28.     for i in range(n - 1):
  29.         cur = seq[i]
  30.         if cur in seen:
  31.             next = i - seen[cur]
  32.             seen[cur] = i
  33.             seq.append(next)
  34.         else:
  35.             seq.append(0)
  36.             seen[cur] = i
  37.  
  38.     return seq
  39.  
  40. # Thank you for the article
Advertisement
Add Comment
Please, Sign In to add comment