Consecutive Number Sequences

Author

Eric W. Weisstein
December 6, 2021

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

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

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

Forward consecutive

SetAttributes[ConsecutiveIntegers,Listable]
ConsecutiveIntegers[n_,b_:10]:=FromDigits[Flatten[IntegerDigits[#,b]&/@Range[n]],b]

ConsecutiveIntegers1[1]:=1
ConsecutiveIntegers1[n_]:=ConsecutiveIntegers1[n]=ConsecutiveIntegers1[n-1] 10^(IntegerLength[n])+n

n=64986;
c=0;
Do[c=c 10^(IntegerLength[k])+k,{k,n}];
c

Timing

IntegerLength[a1=ConsecutiveIntegers[10^3]]//Timing

ConsecutiveIntegers[64986];//Timing

IntegerLength[a2=ConsecutiveIntegers1[10^3]]//Timing

a1==a2

n=64986;
c=0;
Do[c=c 10^(IntegerLength[k])+k,{k,n}];//Timing

c==ConsecutiveIntegers[64986]

n++;
c=c 10^(IntegerLength[n])+n;//Timing

c==ConsecutiveIntegers[64987]

Base 10

For n<10,

Sum[k 10^(n-k),{k,n}]

ConsecutiveForward[n_]:=(1/81) (-10+(10^(1+n))-9 n)

ConsecutiveIntegers[Range[10]]

No primes in first 13,500 terms

Base 2

<<Utilities`Plot`

Remove[NaryPlot]

ConsecutiveIntegers[Range[10],2]

Show[PixelPerfect[Reverse/@Transpose[NaryPlot[ConsecutiveIntegers[Range[90],2]]],BlockSize->1]]

From NKS, p. 913:

Show[PixelPerfect[Partition[Flatten[IntegerDigits[ConsecutiveIntegers[1000,2],2]],256],BlockSize->2]]

Show[PixelPerfect[Partition[Flatten[Table[IntegerDigits[i,2],{i,1000}]],256],BlockSize->2]]

ListPlot[FoldList[Plus,0,Flatten[Table[IntegerDigits[i,2],{i,100}]]],
PlotJoined->True,PlotStyle->Red]

Show[GraphicsArray[
ListPlot[FoldList[Plus,0,2Flatten[Table[#[IntegerDigits[i,2]],{i,8250}]]-1],
PlotJoined->True,PlotStyle->Red,DisplayFunction->Identity]&/@{Identity,Rest}]]

Reverse consecutive

Sequence

https://oeis.org/A000422

ReverseConsecutiveIntegers[n_]:=FromDigits[Flatten[IntegerDigits/@Range[n,1,-1]]]

Table[ReverseConsecutiveIntegers[n],{n,10}]

2-digit

Sum[k 10^(k-1),{k,n}]

ConsecutiveReverse[n_]:=(1/81) (1-(10^n)+9 (10^n) n)

Table[ConsecutiveReverse[n],{n,9}]

n-digit for small n

https://www.mersenneforum.org/showthread.php?p=594527#post594527

#constant values (note that they are = Smr(99), Smr(999) and so on)
c2=(98*10^191+879*10^10+121)/99^2
c3=(998*10^2701-989)/999^2*10^191+c2
c4=(9998*10^36001-9989)/9999^2*10^2892+c3
c5=(99998*10^450001-99989)/99999^2*10^38893+c4

# Now, Smr() for 2-digit n values, for 3-, 4-, 5-, 6-digit (and can be extended, now that you see the rules):
Smr2(n)=((n*99-1)*10^(2*n-19)-89)/99^2*10^10+(8*10^10+1)/9^2
Smr3(n)=((n*999-1)*10^(3*n-299)-989)/999^2*10^191+c2
Smr4(n)=((n*9999-1)*10^(4*n-3999)-9989)/9999^2*10^2892+c3
Smr5(n)=((n*99999-1)*10^(5*n-49999)-99989)/99999^2*10^38893+c4
Smr6(n)=((n*999999-1)*10^(6*n-599999)-999989)/999999^2*10^488894+c5

((n*99-1)*10^(2*n-19)-89)/99^2*10^10+(8*10^10+1)/9^2//FullSimplify

With[{c2=(98*10^191+879*10^10+121)/99^2},((n*999-1)*10^(3*n-299)-989)/999^2*10^191+c2]//FullSimplify

With[{c2=(98*10^191+879*10^10+121)/99^2},With[{c3=(998*10^2701-989)/999^2*10^191+c2},((n*9999-1)*10^(4*n-3999)-9989)/9999^2*10^2892+c3]]//FullSimplify

Primes

https://oeis.org/A176024

None other primes up to 37800 (E.W. Weisstein, Apr. 6, 2010)

l={82,37765};

IntegerLength[ReverseConsecutiveIntegers[Last[l]]]

Print[{#,IntegerLength[#],PrimeQ[ReverseConsecutiveIntegers[#]]//Timing}]&/@l;

https://www.mersenneforum.org/showthread.php?p=594527#post594527

I wrote a different sieve for Smr(n), sieved and (with Ryan) we will test the survivors up to n<=500000 for starters.

Consecutive odd

No others < 8065

ConsecutiveOdd[n_]:=FromDigits[Flatten[IntegerDigits/@Range[1,2n-1,2]]]

l={2,10,16,34,49,2570};

Do[
Print[{i,l[[i]],PrimeQ[ConsecutiveOdd[l[[i]]]]//Timing}],
{i,Length[l]}
]

Digits[ConsecutiveOdd[Last[l]]]

Consecutive square

No others < 5576

ConsecutiveSquares[n_]:=FromDigits[Flatten[IntegerDigits/@(Range[n]^2)]]

Flatten[Position[ConsecutiveSquares/@Range[200],_?PrimeQ]]//Timing

l={3};

Do[
Print[{i,l[[i]],PrimeQ[ConsecutiveSquares[l[[i]]]]//Timing}],
{i,Length[l]}
]

Digits[ConsecutivePrimes[Last[l]]]

Consecutive triangular

TriangularNumber[n_]:=n(n+1)/2
SetAttributes[TriangularNumberc,Listable];

ConsecutiveTriangular[n_]:=FromDigits[Flatten[IntegerDigits/@(TriangularNumber[Range[n]])]]

Flatten[Position[ConsecutiveTriangular/@Range[10^3],_?PrimeQ]]//Timing

Flatten[Position[ConsecutiveTriangular/@Range[10^4],_?PrimeQ]]//Timing

ConsecutiveTriangular/@{2,6}

Consecutive Fibonacci

ConsecutiveFibonacci[n_]:=FromDigits[Flatten[IntegerDigits/@(Fibonacci[Range[n]])]]

ConsecutiveFibonacci/@Range[10]

Flatten[Position[ConsecutiveFibonacci/@Range[10^2],_?PrimeQ]]//Timing

ConsecutiveFibonacci/@{2,4}

Flatten[Position[ConsecutiveFibonacci/@Range[300],_?PrimeQ]]//Timing

Flatten[Position[ConsecutiveFibonacci/@Range[350],_?PrimeQ]]//Timing

Flatten[Position[ConsecutiveFibonacci/@Range[400],_?PrimeQ]]//Timing

Select[Range[401,450],PrimeQ[ConsecutiveFibonacci[#]]&]//Timing

Select[Range[451,500],PrimeQ[ConsecutiveFibonacci[#]]&]//Timing

Do[t=PrimeQ[f=ConsecutiveFibonacci[n]]//Timing;
Print[{t[[1]],n,IntegerLength[f]}];If[t[[2]]===True,Print["PRIME"]],{n,501,1000}]

Demlo numbers

Simplify[10^(n-1)ConsecutiveForward[n]+ConsecutiveReverse[n-1]]

Simplify[Sqrt[%],n>0]

Repunit[n_]:=(1/9) (-1+(10^n))

Table[Repunit[n],{n,9}]

Demlo[n_]:=Repunit[n]^2

Table[Demlo[n],{n,9}]

FullSimplify[Sum[10^k Repunit[n],{k,0,n-1}]]

DemloList[n_]:=PadLeft[#,2n-1]&/@NestList[Append[#,0]&,Table[1,{n}],n-1]

DemloList[5]//TableForm

Plus@@DemloList[5]