Cody

# Problem 713. Find the maximum number of decimal places in a set of numbers

Solution 2048992

Submitted on 6 Dec 2019 by Jonas Oliveira
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
x = [1.000 1.04 0.22 10.1; 2.05 2.33 4.1 1000.31; 5.00010 6.429 7.492 8.0]; y_correct = 4; assert(isequal(find_max_sigdec(x),y_correct))

x1 = 0 y1 = 1 y2 = 1 y3 = 0 y4 = 0 x1 = 0 0.0500 y1 = 3 y2 = 1 y3 = 2 y4 = 0 2 x1 = 0 0.0500 0.0001 y1 = 5 y2 = 1 y3 = 4 y4 = 0 2 4 x1 = 0 0.0500 0.0001 0.0400 y1 = 3 y2 = 1 y3 = 2 y4 = 0 2 4 2 y = 4

2   Pass
N = randi(6,1); x1 = rand(1,100); for k = 1:100 x(1,k) = round(x1(1,k)*10^N)/10^N; end assert(isequal(find_max_sigdec(x), N))

x1 = 0.3000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 x1 = 0.3000 0 y1 = 1 y2 = 1 y3 = 0 y4 = 1 0 x1 = 0.3000 0 0.1000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 x1 = 0.3000 0 0.1000 0.5000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 y1 = 1 y2 = 1 y3 = 0 y4 = 1 0 1 1 1 1 1 1 0 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 x1 = 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Column 19 0.8000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 20 0.8000 0.3000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 21 0.8000 0.3000 0.3000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 22 0.8000 0.3000 0.3000 0.4000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 23 0.8000 0.3000 0.3000 0.4000 0.7000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 24 0.8000 0.3000 0.3000 0.4000 0.7000 0.5000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 25 0.8000 0.3000 0.3000 0.4000 0.7000 0.5000 0.3000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 26 0.8000 0.3000 0.3000 0.4000 0.7000 0.5000 0.3000 0 y1 = 1 y2 = 1 y3 = 0 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 27 0.8000 0.3000 0.3000 0.4000 0.7000 0.5000 0.3000 0 0.9000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 28 0.8000 0.3000 0.3000 0.4000 0.7000 0.5000 0.3000 0 0.9000 0.5000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 29 0.8000 0.3000 0.3000 0.4000 0.7000 0.5000 0.3000 0 0.9000 0.5000 0.1000 y1 = 2 y2 = 1 y3 = 1 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000 0.9000 0.5000 0.6000 0.8000 0 0.1000 0.7000 0.7000 0.3000 0.9000 0.4000 0.4000 0.9000 0.5000 Columns 19 through 30 0.8000 0.3000 0.3000 0.4000 0.7000 0.5000 0.3000 0 0.9000 0.5000 0.1000 0 y1 = 1 y2 = 1 y3 = 0 y4 = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 x1 = Columns 1 through 18 0.3000 0 0.1000 0.5000...

3   Pass
N = randi(6,1); a = rand(5,20); for k = 1:20 for m = 1:5 x(m,k) = round(a(m,k)*10^N)/10^N; end end assert(isequal(find_max_sigdec(x), N))

x1 = 0.6470 y1 = 4 y2 = 1 y3 = 3 y4 = 3 x1 = 0.6470 0.8600 y1 = 3 y2 = 1 y3 = 2 y4 = 3 2 x1 = 0.6470 0.8600 0.8900 y1 = 3 y2 = 1 y3 = 2 y4 = 3 2 2 x1 = 0.6470 0.8600 0.8900 0.3760 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 0.7970 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 0.7970 0.5890 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 0.7970 0.5890 0.1870 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 0.7970 0.5890 0.1870 0.2310 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 3 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 0.7970 0.5890 0.1870 0.2310 0.1230 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 0.7970 0.5890 0.1870 0.2310 0.1230 0.7520 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 0.7970 0.5890 0.1870 0.2310 0.1230 0.7520 0.8610 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 x1 = 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 0.7970 0.5890 0.1870 0.2310 0.1230 0.7520 0.8610 0.7320 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 x1 = Columns 1 through 18 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 0.7970 0.5890 0.1870 0.2310 0.1230 0.7520 0.8610 0.7320 Column 19 0.8470 y1 = 4 y2 = 1 y3 = 3 y4 = 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 x1 = Columns 1 through 18 0.6470 0.8600 0.8900 0.3760 0.5920 0.9910 0.6990 0.2560 0.1220 0.7480 0.7970 0.5890 0.1870 0.2310 0.1230 0.7520 0.8610 0.7320 Columns 19 through 20 0.8470 0.7500 y1 = 3 y2 = 1 y3 = 2 y4 = 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 y = 3

4   Pass
x = 1; assert(isequal(find_max_sigdec(x), 0))

x1 = 0 y1 = 1 y2 = 1 y3 = 0 y4 = 0 y = 0