Finding the Particular digit of Pi using TakeWhile
Clash 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.
list-manipulation
add a comment |Â
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.
list-manipulation
add a comment |Â
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.
list-manipulation
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.
list-manipulation
edited Sep 2 at 18:34
AccidentalFourierTransform
4,398838
4,398838
asked Sep 2 at 18:23
Bignya ranjan Pathi
254
254
add a comment |Â
add a comment |Â
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]]
add a comment |Â
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
add a comment |Â
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]]
add a comment |Â
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]]
add a comment |Â
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]]
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]]
answered Sep 2 at 18:37
AccidentalFourierTransform
4,398838
4,398838
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
... 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
edited Sep 2 at 20:02
answered Sep 2 at 19:55
kglr
159k8183382
159k8183382
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password