Langford's Problem

Author

Eric W. Weisstein
October 15, 2021

This notebook downloaded from http://mathworld.wolfram.com/notebooks/IntegerSequences/LangfordsProblem.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/LangfordsProblem.html.

©2021 Wolfram Research, Inc. except for portions noted otherwise

Code

Modified from Stan Wagon, Oct. 15, 2021

LangfordQ[L_]:=Module[{n=Length[L]/2,pp},
Table[pp=Position[L,i];First[pp[[2]]-pp[[1]]-1],{i,n}]==Range[n]
]

Not necessarily lexicographically smallest:

LangfordSequence[n_]:=Module[
{
x=Ceiling[n/4],
a,b,c,d,p,q,r,s
},
If[!MatchQ[Mod[n,4],0|3],Return[{}]];
a={2x-1};
b={4x-2};
c={4x-1};
d={4x};
p=Select[Complement[Range[0,a[[1]]],{0,a[[1]]}],OddQ];
q=Select[Complement[Range[0,a[[1]]],{0,a[[1]]}],EvenQ];
r=Select[Complement[Range[a[[1]],b[[1]]],{a[[1]],b[[1]]}],OddQ];
s=Select[Complement[Range[a[[1]],b[[1]]],{a[[1]],b[[1]]}],EvenQ];Join@@Which[
Mod[n,4]===0,
	{Reverse[s],Reverse[p],b,p,c,s,d,Reverse[r],Reverse[q],b,a,q,c,r,a,d},
Mod[n,4]===3,
	{Reverse[s],Reverse[p],b,p,c,s,a,Reverse[r],Reverse[q],b,a,q,c,r}
]
]

LangfordSequence[3]

LangfordQ[%]

LangfordSequence[4]

LangfordQ[%]

Sequences

DeleteCases[FromDigits/@Table[LangfordSequence[n],{n,10}],0]

seq=Length/@Table[LangfordSequence[n],{n,20}]

A047451:

DeleteCases[seq,0]

gf=x FindGeneratingFunction[seq,x]

FullSimplify[SeriesCoefficient[gf,{x,0,n}],Mod[n,4]==0||Mod[n,4]==3]