Finding the Particular digit of Pi using TakeWhile

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












TakeWhile[First[RealDigits[Pi, 10, 100]], # != 7 &]


This is used to calculate the first occurrence of 7 but how to get the 20th occurrence of 7.







share|improve this question


























    up vote
    2
    down vote

    favorite












    TakeWhile[First[RealDigits[Pi, 10, 100]], # != 7 &]


    This is used to calculate the first occurrence of 7 but how to get the 20th occurrence of 7.







    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      TakeWhile[First[RealDigits[Pi, 10, 100]], # != 7 &]


      This is used to calculate the first occurrence of 7 but how to get the 20th occurrence of 7.







      share|improve this question














      TakeWhile[First[RealDigits[Pi, 10, 100]], # != 7 &]


      This is used to calculate the first occurrence of 7 but how to get the 20th occurrence of 7.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 2 at 18:34









      AccidentalFourierTransform

      4,398838




      4,398838










      asked Sep 2 at 18:23









      Bignya ranjan Pathi

      254




      254




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote













          In three steps so that it is easier to understand what's going on:



          First[RealDigits[Pi, 10, 1000]] // Short
          Position[%, 7][[20, 1]]
          %%[[1 ;; % - 1]]





          share|improve this answer



























            up vote
            3
            down vote













            ... using TakeWhile:



            ClearAll[digitsUpToMthK]
            digitsUpToMthK[mth_, k_, n_] := Module[t = 0,
            TakeWhile[First[RealDigits[Pi, 10, n]], Or[# != k, (++t) < mth] &]]


            Examples:



            digitsUpToMthK[3, 7, 10000]



            3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9




            Length @ digitsUpToMthK[20, 7, 1000]



            301




            Short @ digitsUpToMthK[20, 7, 1000]



            3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8,

            << 230 >>,

            4, 8, 6, 1, 0, 4, 5, 4, 3, 2, 6, 6, 4, 8, 2, 1, 3, 3, 9, 3, 6, 0, 7, 2, 6, 0, 2, 4, 9, 1, 4, 1, 2, 7, 3




            If you need the position of $m$th occurence of a given digit, you can use LengthWhile:



            ClearAll[posOfMthK]
            posOfMthK[mth_, k_, n_] := Module[t = 0,
            1 + LengthWhile[First[RealDigits[Pi, 10, n]], Or[# != k, (++t) < mth] &]]


            Examples:



            posOfMthK[20, 7, 100000]



            302




            posOfMthK[100, 3, 100000]



            937







            share|improve this answer






















              Your Answer




              StackExchange.ifUsing("editor", function ()
              return StackExchange.using("mathjaxEditing", function ()
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
              );
              );
              , "mathjax-editing");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "387"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181116%2ffinding-the-particular-digit-of-pi-using-takewhile%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              4
              down vote













              In three steps so that it is easier to understand what's going on:



              First[RealDigits[Pi, 10, 1000]] // Short
              Position[%, 7][[20, 1]]
              %%[[1 ;; % - 1]]





              share|improve this answer
























                up vote
                4
                down vote













                In three steps so that it is easier to understand what's going on:



                First[RealDigits[Pi, 10, 1000]] // Short
                Position[%, 7][[20, 1]]
                %%[[1 ;; % - 1]]





                share|improve this answer






















                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote









                  In three steps so that it is easier to understand what's going on:



                  First[RealDigits[Pi, 10, 1000]] // Short
                  Position[%, 7][[20, 1]]
                  %%[[1 ;; % - 1]]





                  share|improve this answer












                  In three steps so that it is easier to understand what's going on:



                  First[RealDigits[Pi, 10, 1000]] // Short
                  Position[%, 7][[20, 1]]
                  %%[[1 ;; % - 1]]






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 2 at 18:37









                  AccidentalFourierTransform

                  4,398838




                  4,398838




















                      up vote
                      3
                      down vote













                      ... using TakeWhile:



                      ClearAll[digitsUpToMthK]
                      digitsUpToMthK[mth_, k_, n_] := Module[t = 0,
                      TakeWhile[First[RealDigits[Pi, 10, n]], Or[# != k, (++t) < mth] &]]


                      Examples:



                      digitsUpToMthK[3, 7, 10000]



                      3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9




                      Length @ digitsUpToMthK[20, 7, 1000]



                      301




                      Short @ digitsUpToMthK[20, 7, 1000]



                      3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8,

                      << 230 >>,

                      4, 8, 6, 1, 0, 4, 5, 4, 3, 2, 6, 6, 4, 8, 2, 1, 3, 3, 9, 3, 6, 0, 7, 2, 6, 0, 2, 4, 9, 1, 4, 1, 2, 7, 3




                      If you need the position of $m$th occurence of a given digit, you can use LengthWhile:



                      ClearAll[posOfMthK]
                      posOfMthK[mth_, k_, n_] := Module[t = 0,
                      1 + LengthWhile[First[RealDigits[Pi, 10, n]], Or[# != k, (++t) < mth] &]]


                      Examples:



                      posOfMthK[20, 7, 100000]



                      302




                      posOfMthK[100, 3, 100000]



                      937







                      share|improve this answer


























                        up vote
                        3
                        down vote













                        ... using TakeWhile:



                        ClearAll[digitsUpToMthK]
                        digitsUpToMthK[mth_, k_, n_] := Module[t = 0,
                        TakeWhile[First[RealDigits[Pi, 10, n]], Or[# != k, (++t) < mth] &]]


                        Examples:



                        digitsUpToMthK[3, 7, 10000]



                        3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9




                        Length @ digitsUpToMthK[20, 7, 1000]



                        301




                        Short @ digitsUpToMthK[20, 7, 1000]



                        3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8,

                        << 230 >>,

                        4, 8, 6, 1, 0, 4, 5, 4, 3, 2, 6, 6, 4, 8, 2, 1, 3, 3, 9, 3, 6, 0, 7, 2, 6, 0, 2, 4, 9, 1, 4, 1, 2, 7, 3




                        If you need the position of $m$th occurence of a given digit, you can use LengthWhile:



                        ClearAll[posOfMthK]
                        posOfMthK[mth_, k_, n_] := Module[t = 0,
                        1 + LengthWhile[First[RealDigits[Pi, 10, n]], Or[# != k, (++t) < mth] &]]


                        Examples:



                        posOfMthK[20, 7, 100000]



                        302




                        posOfMthK[100, 3, 100000]



                        937







                        share|improve this answer
























                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          ... using TakeWhile:



                          ClearAll[digitsUpToMthK]
                          digitsUpToMthK[mth_, k_, n_] := Module[t = 0,
                          TakeWhile[First[RealDigits[Pi, 10, n]], Or[# != k, (++t) < mth] &]]


                          Examples:



                          digitsUpToMthK[3, 7, 10000]



                          3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9




                          Length @ digitsUpToMthK[20, 7, 1000]



                          301




                          Short @ digitsUpToMthK[20, 7, 1000]



                          3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8,

                          << 230 >>,

                          4, 8, 6, 1, 0, 4, 5, 4, 3, 2, 6, 6, 4, 8, 2, 1, 3, 3, 9, 3, 6, 0, 7, 2, 6, 0, 2, 4, 9, 1, 4, 1, 2, 7, 3




                          If you need the position of $m$th occurence of a given digit, you can use LengthWhile:



                          ClearAll[posOfMthK]
                          posOfMthK[mth_, k_, n_] := Module[t = 0,
                          1 + LengthWhile[First[RealDigits[Pi, 10, n]], Or[# != k, (++t) < mth] &]]


                          Examples:



                          posOfMthK[20, 7, 100000]



                          302




                          posOfMthK[100, 3, 100000]



                          937







                          share|improve this answer














                          ... using TakeWhile:



                          ClearAll[digitsUpToMthK]
                          digitsUpToMthK[mth_, k_, n_] := Module[t = 0,
                          TakeWhile[First[RealDigits[Pi, 10, n]], Or[# != k, (++t) < mth] &]]


                          Examples:



                          digitsUpToMthK[3, 7, 10000]



                          3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9




                          Length @ digitsUpToMthK[20, 7, 1000]



                          301




                          Short @ digitsUpToMthK[20, 7, 1000]



                          3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8,

                          << 230 >>,

                          4, 8, 6, 1, 0, 4, 5, 4, 3, 2, 6, 6, 4, 8, 2, 1, 3, 3, 9, 3, 6, 0, 7, 2, 6, 0, 2, 4, 9, 1, 4, 1, 2, 7, 3




                          If you need the position of $m$th occurence of a given digit, you can use LengthWhile:



                          ClearAll[posOfMthK]
                          posOfMthK[mth_, k_, n_] := Module[t = 0,
                          1 + LengthWhile[First[RealDigits[Pi, 10, n]], Or[# != k, (++t) < mth] &]]


                          Examples:



                          posOfMthK[20, 7, 100000]



                          302




                          posOfMthK[100, 3, 100000]



                          937








                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Sep 2 at 20:02

























                          answered Sep 2 at 19:55









                          kglr

                          159k8183382




                          159k8183382



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181116%2ffinding-the-particular-digit-of-pi-using-takewhile%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              Long meetings (6-7 hours a day): Being “babysat” by supervisor

                              Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                              Confectionery