I read that the string 36541622473 occurs in π(pi) at position 36541622473, counting from the first digit after the decimal point. So I want to check that with the code below. It runs but doesn't return anything. What is wrong with it?

pi = Characters[ToString@N[Pi, 36541622473 + 20]];
pos = SequencePosition[pi, First[RealDigits[36541622473]]]

Update: This is another code that I used but faced the same problem.

pi = N[Pi, 36541622473 + 20];
piList = First[RealDigits[pi]];
SequencePosition[piList, First[RealDigits[36541622473]]]
  • 1
    $\begingroup$ Does RealDigits return strings? Isn’t your pi a list of character strings? Why not use RealDigits on Pi? $\endgroup$
    – Michael E2
    Apr 24, 2021 at 16:32
  • $\begingroup$ @MichaelE2 I added an update the orignal code. $\endgroup$
    – emnha
    Apr 24, 2021 at 16:35
  • 3
    $\begingroup$ Why on earth would you expect a general use mathematical software system to return this in a time any less than hours of computation? Easier just to download a dataset with the required range of digits and search that directly. $\endgroup$
    – ciao
    Apr 24, 2021 at 17:23
  • 2
    $\begingroup$ @anhnha - I'd venture that "...it finniish..." is more like "...it quits the kernel..." due to memory exhaustion. This can look like it "...doesn't return anything." $\endgroup$
    – ciao
    Apr 24, 2021 at 20:44
  • 1
    $\begingroup$ it is interesting to ask how one could use Mathematica to generate the digits of $\pi$ this far without exhausting memory, though (even if it took a long time), which is essentially what this question is doing! $\endgroup$
    – thorimur
    Apr 25, 2021 at 0:16

1 Answer 1

checkPi[n_] := 
       ToString@n, "&numberOfDigits=", ToString@IntegerLength@n]][[1, 
      2]]] == n;



checkPi /@ {1, 16470, 44899, 79873884, 711939213, 36541622473, 
      45677255610, 62644957128, 656430109694}

{True, True, True, True, True, True, True, True, True}

  • 1
    $\begingroup$ What to do if I'm looking for a sequence that starts with zero? $\endgroup$
    – Roman
    Apr 25, 2021 at 12:35
  • $\begingroup$ @Roman - by convention, these are not written in that form (you'd not answer the question "how far?" with "000005 km", yes?). $\endgroup$
    – ciao
    Apr 25, 2021 at 18:04
  • 1
    $\begingroup$ @ciao But I might want to search for the first occurrence of the sequence of digits 000005 $\endgroup$ Apr 26, 2021 at 1:16
  • $\begingroup$ @rohitNamjoshi : that may well be so, but clearly that kind of search is not what the question is about. In any case, the same code can trivially be changed to do naive search. $\endgroup$
    – ciao
    Apr 26, 2021 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.