Cody

Problem 44309. Pi Digit Probability

Solution 1311158

Submitted on 23 Oct 2017 by cokakola
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

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

3 1 1 1 4 1 1 2 5 1 9 1 2 1 6 1 5 2 3 2 5 3 8 1 9 2 7 1 9 3 3 3 2 2 3 4 8 2 4 2 6 2 2 3 6 3 4 3 3 5 3 6 8 3 3 7 2 4 7 2 9 4 5 4 0 1 2 5 8 4 8 5 4 4 1 3 9 5 7 3 1 4 6 4 9 6 3 8 9 7 9 8 3 9 7 4 5 5 1 5 0 2 5 6 8 6 2 6 0 3 9 9 7 5 4 5 9 10 4 6 4 7 5 7 9 11 2 7 3 10 0 4 7 6 8 7 1 6 6 5 4 8 0 5 6 6 2 8 8 8 6 7 2 9 0 6 8 9 9 12 9 13 8 10 6 8 2 10 8 11 0 7 3 11 4 9 8 12 2 11 5 8 3 12 4 10 2 12 1 7 1 8 7 7 0 8 6 9 7 8

2   Pass
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 1 1 1 4 1 1 2 5 1 9 1 2 1 6 1 5 2 3 2 5 3 8 1 9 2 7 1 9 3 3 3 2 2 3 4 8 2 4 2 6 2 2 3 6 3 4 3 3 5 3 6 8 3 3 7 2 4 7 2 9 4 5 4 0 1 2 5 8 4 8 5 4 4 1 3 9 5 7 3 1 4 6 4 9 6 3 8 9 7 9 8 3 9 7 4 5 5 1 5 0 2 5 6 8 6 2 6 0 3 9 9 7 5 4 5 9 10 4 6 4 7 5 7 9 11 2 7 3 10 0 4 7 6 8 7 1 6 6 5 4 8 0 5 6 6 2 8 8 8 6 7 2 9 0 6 8 9 9 12 9 13 8 10 6 8 2 10 8 11 0 7 3 11 4 9 8 12 2 11 5 8 3 12 4 10 2 12 1 7 1 8 7 7 0 8 6 9 7 8 9 14 8 13 2 13 1 9 4 11 8 14 0 9 8 15 6 10 5 9 1 10 3 13 2 14 8 16 2 15 3 14 0 10 6 11 6 12 4 12 7 9 0 11 9 15 3 15 8 17 4 13 4 14 6 13 0 12 9 16 5 10 5 11 0 13 5 12 8 18 2 16 2 17 3 16 1 11 7 10 2 18 5 13 3 17 5 14 9 17 4 15 0 14 8 19 1 12 2 19 8 20 4 16 8 21 1 13 1 14 1 15 7 11 4 17 5 15 0 15 2 20 8 22 4 18 1 16 0 16 2 21 7 12 0 17 1 17 9 18 3 18 8 23 5 16 2 22 1 18 1 19 0 18 5 17 5 18 5 19 9 19 6 14 4 19 4 20 6 15 2 23 2 24 9 20 4 21 8 24 9 21 5 20 4 22 9 22 3 19 0 19 3 20 8 25 1 20 9 23

3   Pass
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'))))

3 1 1 1 4 1 1 2 5 1 9 1 2 1 6 1 5 2 3 2 5 3 8 1 9 2 7 1 9 3 3 3 2 2 3 4 8 2 4 2 6 2 2 3 6 3 4 3 3 5 3 6 8 3 3 7 2 4 7 2 9 4 5 4 0 1 2 5 8 4 8 5 4 4 1 3 9 5 7 3 1 4 6 4 9 6 3 8 9 7 9 8 3 9 7 4 5 5 1 5 0 2 5 6 8 6 2 6 0 3 9 9 7 5 4 5 9 10 4 6 4 7 5 7 9 11 2 7 3 10 0 4 7 6 8 7 1 6 6 5 4 8 0 5 6 6 2 8 8 8 6 7 2 9 0 6 8 9 9 12 9 13 8 10 6 8 2 10 8 11 0 7 3 11 4 9 8 12 2 11 5 8 3 12 4 10 2 12 1 7 1 8 7 7 0 8 6 9 7 8 9 14 8 13 2 13 1 9 4 11 8 14 0 9 8 15 6 10 5 9 1 10 3 13 2 14 8 16 2 15 3 14 0 10 6 11 6 12 4 12 7 9 0 11 9 15 3 15 8 17 4 13 4 14 6 13 0 12 9 16 5 10 5 11 0 13 5 12 8 18 2 16 2 17 3 16 1 11 7 10 2 18 5 13 3 17 5 14 9 17 4 15 0 14 8 19 1 12 2 19 8 20 4 16 8 21 1 13 1 14 1 15 7 11 4 17 5 15 0 15 2 20 8 22 4 18 1 16 0 16 2 21 7 12 0 17 1 17 9 18 3 18 8 23 5 16 2 22 1 18 1 19 0 18 5 17 5 18 5 19 9 19 6 14 4 19 4 20 6 15 2 23 2 24 9 20 4 21 8 24 9 21 5 20 4 22 9 22 3 19 0 19 3 20 8 25 1 20 9 23 6 16

4   Pass
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'))))

3 1 1 1 4 1 1 2 5 1 9 1 2 1 6 1 5 2 3 2 5 3 8 1 9 2 7 1 9 3 3 3 2 2 3 4 8 2 4 2 6 2 2 3 6 3 4 3 3 5 3 6 8 3 3 7 2 4 7 2 9 4 5 4 0 1 2 5 8 4 8 5 4 4 1 3 9 5 7 3 1 4 6 4 9 6 3 8 9 7 9 8 3 9 7 4 5 5 1 5 0 2 5 6 8 6 2 6 0 3 9 9 7 5 4 5 9 10 4 6 4 7 5 7 9 11 2 7 3 10 0 4 7 6 8 7 1 6 6 5 4 8 0 5 6 6 2 8 8 8 6 7 2 9 0 6 8 9 9 12 9 13 8 10 6 8 2 10 8 11 0 7 3 11 4 9 8 12 2 11 5 8 3 12 4 10 2 12 1 7 1 8 7 7 0 8 6 9 7 8 9 14 8 13 2 13 1 9 4 11 8 14 0 9 8 15 6 10 5 9 1 10 3 13 2 14 8 16 2 15 3 14 0 10 6 11 6 12 4 12 7 9 0 11 9 15 3 15 8 17 4 13 4 14 6 13 0 12 9 16 5 10 5 11 0 13 5 12 8 18 2 16 2 17 3 16 1 11 7 10 2 18 5 13 3 17 5 14 9 17 4 15 0 14 8 19 1 12 2 19 8 20 4 16 8 21 1 13 1 14 1 15 7 11 4 17 5 15 0 15 2 20 8 22 4 18 1 16 0 16 2 21 7 12 0 17 1 17 9 18 3 18 8 23 5 16 2 22 1 18 1 19 0 18 5 17 5 18 5 19 9 19 6 14 4 19 4 20 6 15 2 23 2 24 9 20 4 21 8 24 9 21 5 20 4 22 9 22 3 19 0 19 3 20 8 25 1 20 9 23 6 16 4 23

5   Pass
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'))))

3 1 1 1 4 1 1 2 5 1 9 1 2 1 6 1 5 2 3 2 5 3 8 1 9 2 7 1 9 3 3 3 2 2 3 4 8 2 4 2 6 2 2 3 6 3 4 3 3 5 3 6 8 3 3 7 2 4 7 2 9 4 5 4 0 1 2 5 8 4 8 5 4 4 1 3 9 5 7 3 1 4 6 4 9 6 3 8 9 7 9 8 3 9 7 4 5 5 1 5 0 2 5 6 8 6 2 6 0 3 9 9 7 5 4 5 9 10 4 6 4 7 5 7 9 11 2 7 3 10 0 4 7 6 8 7 1 6 6 5 4 8 0 5 6 6 2 8 8 8 6 7 2 9 0 6 8 9 9 12 9 13 8 10 6 8 2 10 8 11 0 7 3 11 4 9 8 12 2 11 5 8 3 12 4 10 2 12 1 7 1 8 7 7 0 8 6 9 7 8 9 14 8 13 2 13 1 9 4 11 8 14 0 9 8 15 6 10 5 9 1 10 3 13 2 14 8 16 2 15 3 14 0 10 6 11 6 12 4 12 7 9 0 11 9 15 3 15 8 17 4 13 4 14 6 13 0 12 9 16 5 10 5 11 0 13 5 12 8 18 2 16 2 17 3 16 1 11 7 10 2 18 5 13 3 17 5 14 9 17 4 15 0 14 8 19 1 12 2 19 8 20 4 16 8 21 1 13 1 14 1 15 7 11 4 17 5 15 0 15 2 20 8 22 4 18 1 16 0 16 2 21 7 12 0 17 1 17 9 18 3 18 8 23 5 16 2 22 1 18 1 19 0 18 5 17 5 18 5 19 9 19 6 14 4 19 4 20 6 15 2 23 2 24 9 20 4 21 8 24 9 21 5 20 4 22 9 22 3 19 0 19 3 20 8 25 1 20 9 23 6 16 4 23 4 24 2 25 8 26 8 27 1 21 0 20 9 24 7 13 5 21 6 17 6 18 5 22 9 25 3 21 3 22 4 25 4 26 6 19 1 22 2 26 8 28 4 27 7 14 5 23 6 20 4 28 8 29 2 27 3 23 3 24 7 15 8 30 6 21 7 16 8 31 3 25 1 23 6 22 5 24 2 28 7 17 1 24 2 29 0 21 1 25 9 26 0 22 9 27 1 26 4 29 5 25 6 23 4 30 8 32 5 26 6 24 6 25 9 28 2 30 3 26 4 31 6 26 0 23 3 27 4 32 8 33 6 27 1 27 0 24 4 33 5 27 4 34 3 28 2 31 6 28 6 29 4 35 8 34 2 32 1 28 3 29 3 30 9 29 3 31 6 30 0 25 7 18 2 33 6 31 0 26 2 34 4 36 9 30 1 29 4 37 1 30 2 35 7 19 3 32 7 20 2 36 4 38 5 28 8 35 7 21 0 27 0 28 6 32 6 33 0 29 6 34 3 33 1 31 5 29 5 30 8 36 8 37 1 32 7 22 4 39 8 38 8 39 1 33 5 31 2 37 0 30 9 31 2 38 0 31 9 32 6 35 2 39 8 40 2 40 9 33 2 41 5 32 4 40 0 32 9 34 1 34 7 23 1 35 5 33 3 34 6 36 4 41 3 35 6 37 7 24 8 41 9 35 2 42 5 34 9 36 0 33 3 36 6 38 0 34 0 35 1 36 1 37 3 37 3 38 0 36 5 35 3 39 0 37 5 36 4 42 8 42 8 43 2 43 0 38 4 43 6 39 6 40 5 37 2 44 1 38 3 40 8 44 4 44 1 39 4 45 6 41 9 37 5 38 1 40 9 38 4 46 1 41 5 39 1 42 1 43 6 42 0 39 9 39 4 47 3 41 3 42 0 40 5 40 7 25 2 45 7 26 0 41 3 43 6 43 5 41 7 27 5 42 9 40 5 43 9 41 1 44 9 42 5 44 3 44 0 42 9 43 2 46 1 45 8 45 6 44 1 46 1 47 7 28 3 45 8 46 1 48 9 44 3 46 2 47 6 45 1 49 1 50 7 29 9 45 3 47 1 51 0 43 5 45 1 52 1 53 8 47 5 46 4 48 8 48 0 44 7 30 4 49 4 50 6 46 2 48 3 48 7 31 9 46 9 47 6 47 2 49 7 32 4 51 9 48 5 47 6 48 7 33 3 49 5 48 1 54 8 49 8 50 5 49 7 34 5 50 2 50 7 35 2 51 4 52 8 51 9 49 1 55 2 52 2 53 7 36 9 50 3 50 8 52 1 56 8 53 3 51 0 45 1 57 1 58 9 51 4 53 9 52 1 59 2 54 9 53 8 54 3 52 3 53 6 49 7 37 3 54 3 55 6 50 2 55 4 54 4 55 0 46 6 51 5 51 6 52 6 53 4 56 3 56 0 47 8 55 6 54 0 48 2 56 1 60 3 57 9 54 4 57 9 55 4 58 6 55 3 58 9 56 5 52 2 57 2 58 4 59 7 38 3 59 7 39 1 61 9 57 0 49 7 40 0 50 2 59 1 62 7 41 9 58 8 56 6 56 0 51 9 59 4 60 3 60 7 42 0 52 2 60 7 43 7 44 0 53 5 53 3 61 9 60 2 61 1 63 7 45 1 64 7 46 6 57 2 62 9 61 3 62 1 65 7 47 6 58 7 48 5 54 2 63 3 63 8 57 4 61 6 59 7 49 4 62 8 58 1 66 8 59 4 63 6 60 7 50 6 61 6 62 9 62 4 64 0 54 5 55 1 67 3 64 2 64 0 55 0 56 0 57 5 56 6 63 8 60 1 68 2 65 7 51 1 69 4 65 5 57 2 66 6 64 3 65 5 58 6 65 0 58 8 61 2 67 7 52 7 53 8 62 5 59 7 54 7 55 1 70 3 66 4 66 2 68 7 56 5 60 7 57 7 58 8 63 9 63 6 66 0 59 9 64 1 71 7 59 3 67 6 67 3 68 7 60 1 72 7 61 8 64 7 62 2 69 1 73 4 67 6 68 8 65 4 68 4 69 0 60 9 65 0 61 1 74 2 70 2 71 4 70 9 66 5 61 3 69 4 71 3 70 0 62 1 75 4 72 6 69 5 62 4 73 9 67 5 63 8 66 5 64 3 71 7 63 1 76 0 63 5 65 0 64 7 64 9 68 2 72 2 73 7 65 9 69 6 70 8 67 9 70 2 74 5 66 8 68 9 71 2 75 3 72 5 67 4 74 2 76 0 65 1 77 9 72 9 73 5 68 6 71 1 78 1 79 2 77 1 80 2 78 9 ...

Suggested Problems

More from this Author71

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!