OFFSET
0,6
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..100
MAPLE
g:= (n, s)-> `if`(n in s or not (n=0 or isprime(n)), 0, 1):
b:= proc(u, o, t, s) option remember; `if`(u+o=0, g(t, s),
`if`(g(t, s)=1, add(b(u-j, o+j-1, 1, s union {t})
, j=1..u), 0)+ add(b(u+j-1, o-j, t+1, s), j=1..o))
end:
a:= n-> b(n, 0$2, {}):
seq(a(n), n=0..40);
MATHEMATICA
g[n_, s_] := If[MemberQ[s, n] || Not [n == 0 || PrimeQ[n]], 0, 1];
b[u_, o_, t_, s_] := b[u, o, t, s] = If[u + o == 0, g[t, s],
If[g[t, s] == 1, Sum[b[u - j, o + j - 1, 1, s ~Union~ {t}],
{j, 1, u}], 0] + Sum[b[u + j - 1, o - j, t + 1, s], {j, 1, o}]];
a[n_] := b[n, 0, 0, {}];
a /@ Range[0, 40] (* Jean-François Alcover, Mar 29 2021, after Alois P. Heinz *)
PROG
(Python)
from functools import lru_cache
from sympy import isprime
def g(n, s): return int((n == 0 or isprime(n)) and not n in s)
@lru_cache(maxsize=None)
def b(u, o, t, s):
if u + o == 0: return g(t, s)
c1 = sum(b(u-j, o+j-1, 1, tuple(sorted(s+(t, )))) for j in range(1, u+1)) if g(t, s) else 0
return c1 + sum(b(u+j-1, o-j, t+1, s) for j in range(1, o+1))
def a(n): return b(n, 0, 0, tuple())
print([a(n) for n in range(41)]) # Michael S. Branicky, Mar 29 2021 after Alois P. Heinz
CROSSREFS
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Jul 28 2018
STATUS
approved