// This Magma program generates the terms of OEIS sequence A247556. // For 49 terms, use nMax=49, dMax>=72, and aMax>=5989. // For 100 terms, use nMax=100, dMax>=129, and aMax>=40613. // For 1000 terms, use nMax=1000, dMax>=956, and aMax>=23911868. // (Submitted by Jon E. Schoenfield, Jan 24 2015) nMax:=49; dMax:=72; aMax:=5989; aOfst1:=[0]; // store a(n) as aOfst1[n+1] (can't use index=0 in Magma?) DiffUsed:=[false : d in [1..dMax]]; aAvailable:=[true : d in [1..aMax]]; d:=1; // initialize minimum unused difference for n in [1..nMax] do while DiffUsed[d] do d+:=1; end while; aTest:=aOfst1[n]+d; // a(n-1) + d if aAvailable[aTest] then aOfst1[n+1]:=aTest; // a(n) = a(n-1) + d else while true do aTest+:=1; if aAvailable[aTest] then // a(n-1) + r is available if aAvailable[aTest+d] then // a(n-1) + r + d is available aOfst1[n+1]:=aTest; // a(n) = a(n-1) + r break; end if; end if; end while; end if; // update table of used/unused status of small differences: for j in [n-1..0 by -1] do aDiff:=aOfst1[n+1]-aOfst1[j+1]; // a(n)-a(j) if aDiff gt dMax then break; end if; DiffUsed[aDiff]:=true; end for; // update table of available/unavailable status of remaining integers for i in [0..n-1] do temp:=aOfst1[n+1]-aOfst1[i+1]; // a(n)-a(i) for j in [i+1..n] do aAvailable[aOfst1[j+1]+temp]:=false; // (a(j)-a(i))+a(n) is unavailable end for; end for; end for; aOfst1;