cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A350403 Number of solutions to +-1^2 +- 2^2 +- 3^2 +- ... +- n^2 = 0 or 1.

Original entry on oeis.org

1, 1, 0, 0, 0, 0, 2, 2, 2, 5, 2, 2, 10, 13, 43, 86, 114, 193, 274, 478, 860, 1552, 3245, 5808, 10838, 18628, 31048, 55626, 100426, 188536, 372710, 696164, 1298600, 2376996, 4197425, 7826992, 14574366, 27465147, 53072709, 100061106, 187392994, 351329160
Offset: 0

Views

Author

Ilya Gutkovskiy, Dec 29 2021

Keywords

Examples

			a(8) = 2: +1^2 - 2^2 - 3^2 + 4^2 - 5^2 + 6^2 + 7^2 - 8^2 =
          -1^2 + 2^2 + 3^2 - 4^2 + 5^2 - 6^2 - 7^2 + 8^2 = 0.
		

Crossrefs

Programs

  • Maple
    b:= proc(n, i) option remember; `if`(n>i*(i+1)*(2*i+1)/6, 0,
          `if`(i=0, 1, b(n+i^2, i-1)+b(abs(n-i^2), i-1)))
        end:
    a:=n-> b(0, n)+b(1, n):
    seq(a(n), n=0..42);  # Alois P. Heinz, Jan 16 2022
  • Mathematica
    b[n_, i_] := b[n, i] = If[n > i*(i + 1)*(2*i + 1)/6, 0,
         If[i == 0, 1, b[n + i^2, i - 1] + b[Abs[n - i^2], i - 1]]];
    a[n_] := b[0, n] + b[1, n];
    Table[a[n], {n, 0, 42}] (* Jean-François Alcover, Mar 01 2022, after Alois P. Heinz *)
  • Python
    from itertools import product
    def a(n):
        if n == 0: return 1
        nn = ["0"] + [str(i)+"**2" for i in range(1, n+1)]
        return sum(eval("".join([*sum(zip(nn, ops+("", )), ())])) in {0, 1} for ops in product("+-", repeat=n))
    print([a(n) for n in range(18)]) # Michael S. Branicky, Jan 16 2022
    
  • Python
    from functools import cache
    @cache
    def b(n, i):
        if n > i*(i+1)*(2*i+1)//6: return 0
        if i == 0: return 1
        return b(n+i**2, i-1) + b(abs(n-i**2), i-1)
    def a(n): return b(0, n) + b(1, n)
    print([a(n) for n in range(43)]) # Michael S. Branicky, Jan 16 2022 after Alois P. Heinz