Well, the title of the question says it all: how to write a code that finds the probability of the digit $k$ in the number $x^n$?
For example, when $x=2$, $n=100$, and $k=7$ we are trying to find how many $7$s there are in the number $2^{100}$. To find the answer I wrote $2^{100}=1267650600228229401496703205376$ and counted the number of $7$s, and did:
$$\frac{\text{number of}\space7\text{s}\space\text{in the number}\space2^{100}}{\text{number of digits}\space 2^{100}}=$$ $$\frac{3}{1+\lfloor\log_{10}\left(2^{100}\right)\rfloor}=\frac{3}{31}\approx0.0967742$$
My thoughts for in the code:
- The number of digits in a number $p$ can be found using
1+Floor[Log10[p]] - The r'th digit in the number $p$ can be found by using
IntegerDigits[p][[r]] - In order to check a table of numbers for there probability we can use
ParallelTable[If[TrueQ[], n, Nothing], {n, ,}]
But how to combine the ideas from above, I do not know.
PowerModand the fact that the number of digits of $x^n$ is given byFloor[n Log10@x] + 1may be useful here. $\endgroup$