Cody

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

Solution 2565342

Submitted on 16 Jun 2020 by Raúl Ibáñez Couoh
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))

a = 1×1 cell array {[0]} a = 1×2 cell array {[0]} {[0.0500]} a = 1×3 cell array {[0]} {[0.0500]} {[1.0000e-04]} a = 1×4 cell array {[0]} {[0.0500]} {[1.0000e-04]} {[0.0400]} a = 4×1 cell array {[ 0]} {[ 0.0500]} {[1.0000e-04]} {[ 0.0400]} n = [] b = 0 d = '0' n = -1 b = 0.050000000000000 d = '0.05' n = -1 2 b = 9.999999999976694e-05 d = '0.0001' n = -1 2 4 b = 0.040000000000000 d = '0.04' n = -1 2 4 2 y = 0 y = 4 y = 4 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))

a = 1×1 cell array {[0.580000000000000]} a = 1×2 cell array {[0.580000000000000]} {[0.610000000000000]} a = 1×3 cell array {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} a = 1×4 cell array {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} a = 1×5 cell array {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} a = 1×6 cell array {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} a = 1×7 cell array {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} a = 1×8 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Column 8 {[0.310000000000000]} a = 1×9 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 9 {[0.310000000000000]} {[0.070000000000000]} a = 1×10 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 10 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} a = 1×11 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 11 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} a = 1×12 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 12 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} a = 1×13 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 13 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} a = 1×14 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} a = 1×15 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Column 15 {[0.690000000000000]} a = 1×16 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Columns 15 through 16 {[0.690000000000000]} {[0.010000000000000]} a = 1×17 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Columns 15 through 17 {[0.690000000000000]} {[0.010000000000000]} {[0.470000000000000]} a = 1×18 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Columns 15 through 18 {[0.690000000000000]} {[0.010000000000000]} {[0.470000000000000]} {[0.790000000000000]} a = 1×19 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Columns 15 through 19 {[0.690000000000000]} {[0.010000000000000]} {[0.470000000000000]} {[0.790000000000000]} {[0.050000000000000]} a = 1×20 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Columns 15 through 20 {[0.690000000000000]} {[0.010000000000000]} {[0.470000000000000]} {[0.790000000000000]} {[0.050000000000000]} {[0.410000000000000]} a = 1×21 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Columns 15 through 21 {[0.690000000000000]} {[0.010000000000000]} {[0.470000000000000]} {[0.790000000000000]} {[0.050000000000000]} {[0.410000000000000]} {[0.620000000000000]} a = 1×22 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Columns 15 through 21 {[0.690000000000000]} {[0.010000000000000]} {[0.470000000000000]} {[0.790000000000000]} {[0.050000000000000]} {[0.410000000000000]} {[0.620000000000000]} Column 22 {[0.410000000000000]} a = 1×23 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Columns 15 through 21 {[0.690000000000000]} {[0.010000000000000]} {[0.470000000000000]} {[0.790000000000000]} {[0.050000000000000]} {[0.410000000000000]} {[0.620000000000000]} Columns 22 through 23 {[0.410000000000000]} {[0.870000000000000]} a = 1×24 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Columns 15 through 21 {[0.690000000000000]} {[0.010000000000000]} {[0.470000000000000]} {[0.790000000000000]} {[0.050000000000000]} {[0.410000000000000]} {[0.620000000000000]} Columns 22 through 24 {[0.410000000000000]} {[0.870000000000000]} {[0.070000000000000]} a = 1×25 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.320000000000000]} {[0.850000000000000]} {[0.240000000000000]} {[0.610000000000000]} {[0.470000000000000]} Columns 15 through 21 {[0.690000000000000]} {[0.010000000000000]} {[0.470000000000000]} {[0.790000000000000]} {[0.050000000000000]} {[0.410000000000000]} {[0.620000000000000]} Columns 22 through 25 {[0.410000000000000]} {[0.870000000000000]} {[0.070000000000000]} {[0.010000000000000]} a = 1×26 cell array Columns 1 through 7 {[0.580000000000000]} {[0.610000000000000]} {[0.930000000000000]} {[0.130000000000000]} {[0]} {[0.160000000000000]} {[0.680000000000000]} Columns 8 through 14 {[0.310000000000000]} {[0.070000000000000]} {[0.32000...

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))

a = 1×1 cell array {[0.304862000000000]} a = 1×2 cell array {[0.304862000000000]} {[0.342638000000000]} a = 1×3 cell array {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} a = 1×4 cell array {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} a = 1×5 cell array {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} a = 1×6 cell array {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} a = 1×7 cell array {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} a = 1×8 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Column 8 {[0.644231000000000]} a = 1×9 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 9 {[0.644231000000000]} {[0.278800000000000]} a = 1×10 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 10 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} a = 1×11 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 11 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} a = 1×12 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 12 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} {[0.161136000000000]} a = 1×13 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 13 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} {[0.161136000000000]} {[0.127984000000000]} a = 1×14 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 14 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} {[0.161136000000000]} {[0.127984000000000]} {[0.606341000000000]} a = 1×15 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 14 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} {[0.161136000000000]} {[0.127984000000000]} {[0.606341000000000]} Column 15 {[0.451221000000000]} a = 1×16 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 14 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} {[0.161136000000000]} {[0.127984000000000]} {[0.606341000000000]} Columns 15 through 16 {[0.451221000000000]} {[0.284772000000000]} a = 1×17 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 14 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} {[0.161136000000000]} {[0.127984000000000]} {[0.606341000000000]} Columns 15 through 17 {[0.451221000000000]} {[0.284772000000000]} {[0.034611000000000]} a = 1×18 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 14 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} {[0.161136000000000]} {[0.127984000000000]} {[0.606341000000000]} Columns 15 through 18 {[0.451221000000000]} {[0.284772000000000]} {[0.034611000000000]} {[0.755886000000000]} a = 1×19 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 14 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} {[0.161136000000000]} {[0.127984000000000]} {[0.606341000000000]} Columns 15 through 19 {[0.451221000000000]} {[0.284772000000000]} {[0.034611000000000]} {[0.755886000000000]} {[0.156652000000000]} a = 1×20 cell array Columns 1 through 7 {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} Columns 8 through 14 {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} {[0.161136000000000]} {[0.127984000000000]} {[0.606341000000000]} Columns 15 through 20 {[0.451221000000000]} {[0.284772000000000]} {[0.034611000000000]} {[0.755886000000000]} {[0.156652000000000]} {[0.101379000000000]} a = 20×1 cell array {[0.304862000000000]} {[0.342638000000000]} {[0.206193000000000]} {[0.646788000000000]} {[0.392115000000000]} {[0.950153000000000]} {[0.583338000000000]} {[0.644231000000000]} {[0.278800000000000]} {[0.632350000000000]} {[0.499497000000000]} {[0.161136000000000]} {[0.127984000000000]} {[0.606341000000000]} {[0.451221000000000]} {[0.284772000000000]} {[0.034611000000000]} {[0.755886000000000]} {[0.156652000000000]} {[0.101379000000000]} n = [] b = 0.304862000000000 d = '0.30486' n = 5 b = 0.342638000000000 d = '0.34264' n = 5 5 b = 0.206193000000000 d = '0.20619' n = 5 5 5 b = 0.646788000000000 d = '0.64679' n = 5 5 5 5 b = 0.392115000000000 d = '0.39211' n = 5 5 5 5 5 b = 0.950153000000000 d = '0.95015' n = 5 5 5 5 5 5 b = 0.583338000000000 d = '0.58334' n = 5 5 5 5 5 5 5 b = 0.644231000000000 d = '0.64423' n = 5 5 5 5 5 5 5 5 b = 0.278800000000000 d = '0.2788' n = 5 5 5 5 5 5 5 5 4 b = 0.632350000000000 d = '0.63235' n = 5 5 5 5 5 5 5 5 4 5 b = 0.499497000000000 d = '0.4995' n = 5 5 5 5 5 5 5 5 4 5 4 b = 0.161136000000000 d = '0.16114' n = 5 5 5 5 5 5 5 5 4 5 4 5 b = 0.127984000000000 d = '0.12798' n = 5 5 5 5 5 5 5 5 4 5 4 5 5 b = 0.606341000000000 d = '0.60634' n = 5 5 5 5 5 5 5 5 4 5 4 5 5 5 b = 0.451221000000000 d = '0.45122' n = 5 5 5 5 5 5 5 5 4 5 4 5 5 5 5 b = 0.284772000000000 d = '0.28477' n = 5 5 5 5 5 5 5 5 4 5 4 5 5 5 5 5 b = 0.034611000000000 d = '0.034611' n = 5 5 5 5 5 5 5 5 4 5 4 5 5 5 5 5 6 b = 0.755886000000000 d = '0.75589' n = 5 5 5 5 5 5 5 5 4 5 4 5 5 5 5 5 6 5 b = 0.156652000000000 d = '0.15665' n = 5 5 5 5 5 5 5 5 4 5 4 5 5 5 5 5 6 5 5 b = 0.101379000000000 d = '0.10138' n = 5 5 5 5 5 5 5 5 4 5 4 5 5 5 5 5 6 5 5 5 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6 y = 6

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

a = 1×1 cell array {[0]} a = 1×1 cell array {[0]} n = [] b = 0 d = '0' n = -1 y = 0

Suggested Problems