Cody

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

Solution 3002539

Submitted on 28 Sep 2020 by Richard Allred
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))

x2a = 3×51 char array ' 1 1.04 0.22 10.1' ' 2.05 2.33 4.1 1000.31' '5.0001 6.429 7.492 8' x3 = 1×12 string array "1" "1.04" "0.22" "10.1" "2.05" "2.33" "4.1" "1000.31" "5.0001" "6.429" "7.492" "8" x4 = 1×12 string array <missing> "04" "22" "1" "05" "33" "1" "31" "0001" "429" "492" <missing> 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))

x2a = '0.27 0.18 0.15 0.76 0.27 0.94 0.22 0.13 0.82 0.76 0.3 0.98 0.81 0.46 0.73 0.43 0.01 0.4 0.28 0.27 0.12 0.8 0.55 0.47 0.81 0.57 0.77 0.94 0.26 0.25 0.9 0.16 0.66 0.27 0.66 0.15 0.06 0.34 0.09 0.34 0.01 0.43 0.91 0.11 0.21 0.86 0.57 0.82 0.07 0.36 0.05 0.01 0.05 0.46 0.4 0.04 0.66 0.66 0.94 0.53 0.96 0.76 0.72 0.05 0.04 0.08 0.93 0.17 0.31 0.33 0.95 0.09 0.47 0.8 0.45 0.96 0.54 0.97 0.7 0.87 0.77 0.03 0.17 0.12 0.49 0.03 0.09 0.6 0.39 0.01 0.98 0.29 0.78 0.18 0.28 0.58 0.35 0.38 0.86 0.82' x3 = 1×100 string array Columns 1 through 18 "0.27" "0.18" "0.15" "0.76" "0.27" "0.94" "0.22" "0.13" "0.82" "0.76" "0.3" "0.98" "0.81" "0.46" "0.73" "0.43" "0.01" "0.4" Columns 19 through 36 "0.28" "0.27" "0.12" "0.8" "0.55" "0.47" "0.81" "0.57" "0.77" "0.94" "0.26" "0.25" "0.9" "0.16" "0.66" "0.27" "0.66" "0.15" Columns 37 through 54 "0.06" "0.34" "0.09" "0.34" "0.01" "0.43" "0.91" "0.11" "0.21" "0.86" "0.57" "0.82" "0.07" "0.36" "0.05" "0.01" "0.05" "0.46" Columns 55 through 72 "0.4" "0.04" "0.66" "0.66" "0.94" "0.53" "0.96" "0.76" "0.72" "0.05" "0.04" "0.08" "0.93" "0.17" "0.31" "0.33" "0.95" "0.09" Columns 73 through 90 "0.47" "0.8" "0.45" "0.96" "0.54" "0.97" "0.7" "0.87" "0.77" "0.03" "0.17" "0.12" "0.49" "0.03" "0.09" "0.6" "0.39" "0.01" Columns 91 through 100 "0.98" "0.29" "0.78" "0.18" "0.28" "0.58" "0.35" "0.38" "0.86" "0.82" x4 = 1×100 string array Columns 1 through 23 "27" "18" "15" "76" "27" "94" "22" "13" "82" "76" "3" "98" "81" "46" "73" "43" "01" "4" "28" "27" "12" "8" "55" Columns 24 through 45 "47" "81" "57" "77" "94" "26" "25" "9" "16" "66" "27" "66" "15" "06" "34" "09" "34" "01" "43" "91" "11" "21" Columns 46 through 67 "86" "57" "82" "07" "36" "05" "01" "05" "46" "4" "04" "66" "66" "94" "53" "96" "76" "72" "05" "04" "08" "93" Columns 68 through 90 "17" "31" "33" "95" "09" "47" "8" "45" "96" "54" "97" "7" "87" "77" "03" "17" "12" "49" "03" "09" "6" "39" "01" Columns 91 through 100 "98" "29" "78" "18" "28" "58" "35" "38" "86" "82" y = 2

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

x2a = 5×231 char array '0.8 0.9 0.7 0.4 0 0.2 0.5 0.8 0.3 0.1 0.6 0.9 0.9 0.7 0.4 0.9 0.4 0.5 0.6 0.2' ' 1 0.8 0.4 0.1 0.9 0.8 0.7 0.7 0.8 0.8 0.2 0.3 0.3 0.4 0.5 0.9 0.8 0.3 0.9 0.4' '0.9 0.4 1 0.6 0.2 0.2 0.3 0.3 0.7 0.1 0.1 0.3 0.2 0.1 0.2 0.4 0.6 1 0.3 0.3' '0.8 0.3 0.4 1 0.7 0.3 0.4 0.2 0 0.6 0.1 0.7 0.3 0.2 0.3 0.4 0.2 0 0.2 0.3' '0.1 0.7 0.5 0.9 0.5 0.1 0.8 0.7 0.3 0.3 0.3 0 0.1 0 0.1 0.6 1 0.5 0.1 0' x3 = 1×100 string array Columns 1 through 20 "0.8" "0.9" "0.7" "0.4" "0" "0.2" "0.5" "0.8" "0.3" "0.1" "0.6" "0.9" "0.9" "0.7" "0.4" "0.9" "0.4" "0.5" "0.6" "0.2" Columns 21 through 40 "1" "0.8" "0.4" "0.1" "0.9" "0.8" "0.7" "0.7" "0.8" "0.8" "0.2" "0.3" "0.3" "0.4" "0.5" "0.9" "0.8" "0.3" "0.9" "0.4" Columns 41 through 60 "0.9" "0.4" "1" "0.6" "0.2" "0.2" "0.3" "0.3" "0.7" "0.1" "0.1" "0.3" "0.2" "0.1" "0.2" "0.4" "0.6" "1" "0.3" "0.3" Columns 61 through 80 "0.8" "0.3" "0.4" "1" "0.7" "0.3" "0.4" "0.2" "0" "0.6" "0.1" "0.7" "0.3" "0.2" "0.3" "0.4" "0.2" "0" "0.2" "0.3" Columns 81 through 100 "0.1" "0.7" "0.5" "0.9" "0.5" "0.1" "0.8" "0.7" "0.3" "0.3" "0.3" "0" "0.1" "0" "0.1" "0.6" "1" "0.5" "0.1" "0" x4 = 1×100 string array Columns 1 through 24 "8" "9" "7" "4" <missing> "2" "5" "8" "3" "1" "6" "9" "9" "7" "4" "9" "4" "5" "6" "2" <missing> "8" "4" "1" Columns 25 through 49 "9" "8" "7" "7" "8" "8" "2" "3" "3" "4" "5" "9" "8" "3" "9" "4" "9" "4" <missing> "6" "2" "2" "3" "3" "7" Columns 50 through 72 "1" "1" "3" "2" "1" "2" "4" "6" <missing> "3" "3" "8" "3" "4" <missing> "7" "3" "4" "2" <missing> "6" "1" "7" Columns 73 through 95 "3" "2" "3" "4" "2" <missing> "2" "3" "1" "7" "5" "9" "5" "1" "8" "7" "3" "3" "3" <missing> "1" <missing> "1" Columns 96 through 100 "6" <missing> "5" "1" <missing> y = 1

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

x2a = '1' x3 = "1" x4 = <missing> y = 0

Suggested Problems

Community Treasure Hunt

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

Start Hunting!