Problem 44309. Pi Digit Probability
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:
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;
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)
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
Solution CommentsShow comments
Problem Recent Solvers485
Deleting an element in a matrix
(Linear) Recurrence Equations - Generalised Fibonacci-like sequences
Find the sides of an isosceles triangle when given its area and height from its base to apex
A Simple Tide Gauge with MATLAB
More from this Author92
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!