# Thread: Maple - Finding numbers on pi

1. ## Maple - Finding numbers on pi

Hello!

I need to find out how many strings of 3 same numbers or more exist on Pi's first 10,000 digits. So I wrote this on Maple:

p := evalf[210](Pi);
cnt := 0;
for i to 210 do
a1 := floor(p);
if a1 = floor((p-a1)*10) then
if a1 = floor(100*(p-a1-0.1*a1)) then
cnt := cnt+1;
while a1 = floor(1000*(p-a1-0.1*a1-0.01*a1)) do
cnt := cnt+1;
p := 10*(p-a1) ;
end do;
end if;
end if;
p := 10*(p-a1);
end do;
cnt

(This one is up to 210 digits, just wanted to check).

When I run, it keeps calculating, but when I stopped (after about 10 minutes) cnt was 70571756... Where is my mistake?

Thank you very much

2. Not quite sure what your code is doing and if you could explain it a bit I might be able to advise you but here is one I wrote. It's very inefficient but I'm discussing it with some folk over on a different forum so may post up a better one later.

A := NULL:
a := NULL:
for k from 0 to 9997 do
a := [floor(evalf[10000]((10^k)*Pi)) mod 10,
floor(evalf[10000]((10^(k+1))*Pi)) mod 10,
floor(evalf[10000]((10^(k+2))*Pi)) mod 10]:
if a[1]=a[2] and a[1]=a[3] then
A := A+1:
k := k+3
end if:
end do:
A;

3. Thank you, it's a very nice way to solve it.

I only have two problems now:

*I can't use mod with irrational numbers (not also modp).
*It should count how many strings of 3 or more. So for instance, if there's a 6 string (low possibilities, but still) - it should recognize it as one.

Thank you, it's a very nice way to solve it.

I only have two problems now:

*I can't use mod with irrational numbers (not also modp).
*It should count how many strings of 3 or more. So for instance, if there's a 6 string (low possibilities, but still) - it should recognize it as one.

Yeah, it takes the floor first so you can use mod. Have you tried it? It seems to work but I don't know how many strings there should be...

If will only recognize a larger string if there is a 7 string one. (which is what the k := k+3 does). As I said I should be posting an updated version hopefully soon.

Have a look at the StringTools package as well.

Yeah, it takes the floor first so you can use mod. Have you tried it? It seems to work but I don't know how many strings there should be...

If will only recognize a larger string if there is a 7 string one. (which is what the k := k+3 does). As I said I should be posting an updated version hopefully soon.

Have a look at the StringTools package as well.
Oh, I see, I thought the 'floor' takes place after the mod... now it's just fine.

Thanks

6. s:=convert(trunc(evalf(Pi*10^10000,10003)), string):
with(StringTools):
R:= [SearchAll([seq(cat(i,i,i),i="0".."9")],s)]:

nops(R);

Not 100% sure how this code works but was given it by someone else.