# A358629 - a(n) is the number of signed permutations W of V = (1, 2, ..., n) such that the dot product V*W = 0. # Python program by Bert Dobbelaere # This function returns a map with the number of solutions for each sum using the remaining numbers marked in the mask # Only positive sums are stored at the cost of some extra complexity, but it saves memory which is the limiting factor def solve(lvl, mask): global cache if lvl==0: return {0:1} if mask in cache: return cache[mask] # mask alone is a unique key, lvl is implied vals={} for b in range(N): if (mask>>b)&1: halfstats=solve(lvl-1,mask & ~(1<=0: if not (x+delta) in vals: vals[x+delta]=0 vals[x+delta] += stats[x] if (x-delta)>=0: if not (x-delta) in vals: vals[x-delta]=0 vals[x-delta] += stats[x] cache[mask]=vals return vals for N in range(1,20+1): cache={} results=solve(N, 2**N-1) if not 0 in results: results[0]=0 print("a(%d) = %d"%(N,results[0]))