Hacker News new | ask | show | jobs
by jacquesm 1254 days ago
The 2 is the first value. And no spoilers.
1 comments

https://oeis.org/A001105 starts with 0 so I guess you don't mean that obvious quadratic.

Could be https://oeis.org/A209303 :

  def f(n):
    return n*n + sum(k*k for k in map(int, str(n)))

  >>> [f(i) for i in range(1, 5)]
  [2, 8, 18, 32]
but I don't know why that entry doesn't start with 0.

Could be https://oeis.org/A190787 :

  >>> import heapq, itertools
  >>> seq = heapq.merge((2**i for i in itertools.count(1, 2)),
              (9*2**i for i in itertools.count(1, 2)))
  >>> list(itertools.islice(seq, 0, 4))
  [2, 8, 18, 32]
Or https://oeis.org/A067051:

  import itertools

  def sigma(n):
    return sum(i for i in range(1, n//2+1) if n % i == 0)

  def seq():
    for n in itertools.count(1):
      if sigma(2*n) % 2 == 0: continue
      if sigma(3*n) % 3 == 0: yield n
      continue

  >>> list(itertools.islice(seq(), 0, 4))
  [2, 8, 18, 32]
The others are either degenerate for 4 points of the A001105 case, or are not so easy to implement in raw Python.
Think chemistry...
I believe you are referring to one of the many listed ways to define https://oeis.org/A001105 , which is even more succinctly expressed as a(n) = 2*n^2. This is the answer I thought you wanted, and which I was avoiding saying.

My underlying point is your sequence was under-specified, and with no clear reason to pick your preferred answer over other answers.

Even knowing it's chemistry, three finite sequences which match your specification are:

  2, 8, 18, 32, 18,  8, 2
  2, 8, 18, 32, 21,  9, 2
  2, 8, 18, 32, 32, 14, 2