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;