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
testsuite not working, please change "assert(isequal(pidigit(N,n)-y_correct<0.0001))" to "assert(abs(pidigit(N,n)-y_correct)<0.0001)"
Thanks, I have made the change
Still missing a ")" in your assert statement
Thanks, I have add ')'
In Solution 1301292 I am finding the same thing as Yona reported (see comment below). "Digits" should mean all digits, including the leading 3. That is the definition required to pass Test 1. But to pass Test 2 and Test 5, it is required to ignore the leading 3. Or else some people have misread the problem statement, which says that the number of digits to inspect is not N, but rather N–1. (Because we're trying to predict the N'th digit.) I count only 15 occurrences of "6" in the first 200 digits, when the leading "3" is included (as it should be).
I can not find a solution without using the symbolic math toolbox ;(
David, Maurício, Yona and mhartma3 check your solutions. They should pass all the test suit now.
Thanks, Mehmet OZC. I suppose that numerically my Solution 1301292 should now pass, but it seems it is failing the new assertion that uses regex to parse the M-file. I guess it is looking for hard-coded solutions that might characteristically contain any of the numbers [101,201,202,203,1001], which are important parameters in your Test Suite. However, inspection of pi reveals that the sequence "101" appears at the 852nd decimal place, "201" appears at the 244th decimal place, etc. So the new assertion might be creating unexpected side-effects.
@David it is somewhat funny but that solution is not failing because of those partial matches in the pi sequence (the regexp command used will disregard partial matches) but rather because of the explicit 1001 value in your commented line (reading "First 1001 digits of pi")
Ah, thanks for the clarification, Alfonso. So it was an unintended side-effect, but not the one I had supposed. That also explains why it didn't disrupt most other solutions.
It is a shame vpa does not work, this could lead to some more interesting challenges
......
You have to provide the number pi as a string as input. This is horrible, however, this is needed, because the symbolic toolbox is not working. Therefore, here is the number:
initPI = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989';
I think the answers to the second and the last tests are wrong, they should be 0.08 and .105 respectively
The question is boring
Pretty sure that there is an error in the test bench or the internet has the PI digits wrong on some sites
- result for the last case must be 0.106.
- if vpa is not accepted this is a silly question.
% 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 commentsProblem Recent Solvers585
Suggested Problems
-
509 Solvers
-
Mersenne Primes vs. All Primes
602 Solvers
-
1568 Solvers
-
964 Solvers
-
1761 Solvers
More from this Author92
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!