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.
testsuite not working, please change "assert(isequal(pidigit(N,n)-y_correct
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.
how do I solve this without using either the Pi value string or symbolic toolbox?
why do I always get this error message:
Undefined function 'vpa' for input arguments of type 'double'.
When running the code in my Matlab version, it works fine
to use vpa function you must have symbolic math toolbox. We cannot use the toolbox on cody.
I think the answer to test suite 3 should be 0.0746 rather than 0.0796.
Kyle, test suite is correct. your code includes decimal point. check your solution
Ah, you're correct. Thanks!
My code passes all tests but the last... I'm getting 0.1050 as a result instead of 0.1060.
can we just do not paste pi and truncate? try something different.
Shouldn't the correct answer for test 2 be 0.08? There are be 16 occurrences of the digit 6 in the first 200 digits. 16/200 = 0.08.
Sorry for that, I have corrected the mistake.
I think this correction is not good. the 201th digit is 6 so only 15 until 200 (when the first digit is 3 and not only the decimal part)
same problem in test 5. need to be 105. (see solution 1292755 and 1292769)
I agree with Yona that the "corrected" solution is now wrong. There are only 15 occurrences of the digit 6 in the first 200 digits. 15/200 = 0.0750. Similarly, the solution to test 5 should be 105/1000 = 0.1050.
Not a particularly cool solution to be proud of, but a string literal would be neither too elegant...
503 Solvers
The Hitchhiker's Guide to MATLAB
2601 Solvers
1992 Solvers
247 Solvers
241 Solvers