# list manipulation – How to improve speed in traversing large arrays of numbers?

I’m trying to find my birthday in ten million digits.
And we want to arrange the numbers in a pi shape.
Of course, I made my birthday (6 digits) visible in the printed image.
The function written is as follows.

``````findPi({a_, b_, c_, d_, e_, f_}, digit_, {precision_, imagesize_, fontsize_}) :=
Module({},
pixel = PixelValuePositions(Rasterize(Text@Style(Pi, Bold, FontFamily -> "Source Serif Pro"),
RasterSize -> precision), 0); pi = First(RealDigits(Pi, 10, digit));
birth = {a, b, c, d, e, f};
pos = SequencePosition(First(RealDigits(Pi, 10, digit)), birth);
mypi = First(
RealDigits(Pi, 10, 500 + Max( pos((1, 2)), Length(pixel) ))   ) ;
pi0 = {Style(Tooltip(3, 1), If(pos((1, 1)) == 1, Red, Blue), Bold,
fontsize), Style("!(*StyleBox(".",nFontSize->14))", Blue, Bold, fontsize)};
n = Floor(0.35 Length(pixel));
pi1 = If(pos((1, 1)) == 1, {}, Table(
Tooltip(mypi((i)), i), {i, 2,
If(pos((1, 1)) - 1 > 2 n, n - 1, pos((1, 1)) - 1)}));
pi22 = If(pos((1, 1)) - 1 > 2 n, Characters("...("), Null);
pi2 = Table(
Style(pi22((i)), Blue, Bold, fontsize + 1), {i, 1, Length(pi22)});
int = If(pos((1, 1)) - 1 > 2 n, pos((1, 1)) - 2 n, Null);
pi33 = If(pos((1, 1)) - 1 > 2 n, RealDigits(int)((1)), Null);
pi3 = Table(
Style(pi33((i)), Blue, Bold, fontsize), {i, 1, Length(pi33)});
pi44 = If(pos((1, 1)) - 1 > 2 n, Characters(")..."), Null);
pi4 = Table(
Style(pi44((i)), Blue, Bold, fontsize + 1), {i, 1, Length(pi44)});
pi5 = If(pos((1, 1)) - 1 > 2 n,
Table(
Tooltip(mypi((i)), i), {i, pos((1, 1)) - n,
pos((1, 1)) - 1} ), {});
pi66 = mypi((pos((1, 1)) ;; pos((1, 2)))); (* my number *)
pi6 = Table(
Style(Tooltip(pi66((i)), pos((1, 1)) + i - 1), Red, Bold,
fontsize), {i, If(pos((1, 1)) == 1, 2, 1), Length(pi66)});
pi7 = If(pos((1, 1)) - 1 > 2 n,
Table(
Tooltip(mypi((i)), i), {i, pos((1, 2)) + 1, Length(mypi)  }),
Table(
Tooltip(mypi((i)), i), {i, pos((1, 2)) + 1, Length(mypi)}) );
pi88 = Characters("...");
pi8 = Table(
Style(pi88((i)), Blue, Bold, fontsize), {i, 1, Length(pi88)});
array = Flatten({pi0, pi1, pi2, pi3, pi4, pi5, pi6, pi7, pi8});
(* pi graph *)
showPlot =  If( Length(pos) == 0,
AspectRatio -> 1),
Show(Graphics@
Style(Text(#1, #2), Bold, fontsize) &, {Take(array,
Length(pixel)), pixel}), ImageSize -> imagesize,
PlotLabel ->
Style(Column({
Row({Spacer(25), "My Happy Birthday ", Style(a, Blue),
Style(b, Blue), ".", Style(c, Blue), Style(d, Blue), ".",
Style(e, Blue), Style(f, Blue), "."}),

Row({Spacer(25), "First appears in the ",
Style(NumberForm(pos((1, 1)), DigitBlock -> 3), Red),
" digit of (Pi) "})}, Alignment -> Center), 30, Bold,
Black))));
findPi({4, 6, 0, 1, 1, 9}, 12000000, {40, 600, 12})
``````

The output image is as follows

However, the speed is too slow to search the number array of pi up to 10 million or 20 million digits.
In particular, using Manipulate makes it even slower. And the program shuts down.

``````Manipulate( findPi({a, b, c, d, e, f}, range, {40, 600, 12});
Row({ Control@{{a, 1, ""}, Table(i, {i, 0, 9})},
Control@{{b, 9, ""}, Table(i, {i, 0, 9})},
Control@{{c, 2, ""}, Table(i, {i, 0, 9})},
Control@{{d, 7, ""}, Table(i, {i, 0, 9})},
Control@{{e, 8, ""}, Table(i, {i, 0, 9})},
Control@{{f, 1, ""}, Table(i, {i, 0, 9})}  ,
Spacer(30),  Control@{{range, 10^7}, { 10^7, 2*10^7}, PopupMenu} }),
ContentSize -> {620, 620} , SaveDefinitions -> True,
AppearanceElements -> None, ContinuousAction -> None )
``````

I want to manipulate the values of a,b,c,d,e,f,range using Manipulate.
And I’m trying to make it into a cdf file.
Is there any way to increase the speed?

Note) I will find the positions of all numeric arrays within the specified search range.
Therefore, the calculation will not stop at the first appearing position.