Problem 44309. Pi Digit Probability
Assume that the next digit of pi constant is determined by the historical digit distribution. What is the probability of next digit (N) being (n).
For example if we consider the first 100 digits of pi, we will see that the digit '3' is occured 12 times. So the probability of the being '3' the 101th digit will be 12/100 = 0.12.
Round the results to four decimals.
Solution Stats
Problem Comments
-
20 Comments
% I used Machin's Formula: pi = 4[4arctan(1/5) - arctan(1/239)] because it was used for speed. But it will not go no more than 16 digits. How can I go beyond 16 digits?
function [PI] = pidigit(N,n)
A = 0;
F = 10^300;
% Machin's Formula: pi = 4[4arctan(1/5) - arctan(1/239)]
x1 = 1/5;
x2 = 1/239;
for K = 0:1000000000
A1 = 4*((-1)^K*x1^(2*K+1)/(2*K+1));
A2 = (-1)^K*x2^(2*K+1)/(2*K+1);
A = A + 4*(A1 - A2)*F;
end
E = abs(pi*F-A)/(pi*F);
PI = sprintf('%.f',A) -'0';
sum(PI(1:N-1) == n)
sum(PI(1:N-1) == n)/(N-1)
end
can't use vpa, so thats annoying. just find online the first bunch of digits of pi, paste them into a character variable, and work from there. I found the digits here :https://www.angio.net/pi/digits/10000.txt
good
Solution Comments
Show commentsGroup

Project Euler II
- 12 Problems
- 51 Finishers
- Find the longest sequence of 1's in a binary sequence.
- Convert given decimal number to binary number.
- Find out sum and carry of Binary adder
- Binary numbers
- Given an unsigned integer x, find the largest y by rearranging the bits in x
- Bit Reversal
- Relative ratio of "1" in binary number
- Binary code (array)
- Converting binary to decimals
- There are 10 types of people in the world
Problem Recent Solvers657
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!