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.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
N = 101;
n = 3;
y_correct = 0.1200;
assert(abs(pidigit(N,n)-y_correct)<0.0001)
assert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\d\.\+\-\*\/]+','match')))) % modified from the comment of Alfonso on https://www.mathworks.com/matlabcentral/cody/problems/44343
|
2 | Fail |
N = 201;
n = 6;
y_correct = 0.0750;
assert(abs(pidigit(N,n)-y_correct)<0.0001)
assert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\d\.\+\-\*\/]+','match'))))
|
3 | Fail |
N = 202;
n = 6;
y_correct = 0.0796;
assert(abs(pidigit(N,n)-y_correct)<0.0001)
assert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\d\.\+\-\*\/]+','match'))))
|
4 | Fail |
N = 203;
n = 6;
y_correct = 0.0792;
assert(abs(pidigit(N,n)-y_correct)<0.0001)
assert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\d\.\+\-\*\/]+','match'))))
|
5 | Fail |
N = 1001;
n = 9;
y_correct = 0.1050;
assert(abs(pidigit(N,n)-y_correct)<0.0001)
assert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\d\.\+\-\*\/]+','match'))))
|
606 Solvers
483 Solvers
Program an exclusive OR operation with logical operators
639 Solvers
Longest run of consecutive numbers
1651 Solvers
518 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!