Cody

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

Solution 1944679

Submitted on 21 Sep 2019 by Vu Thanh Nam
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))

b = 0 0.0400 0.2200 0.1000 0.0500 0.3300 0.1000 0.3100 0.0001 0.4290 0.4920 0 c = 13×6 char array ' 0' ' 0.05' '0.0001' ' 0.04' ' 0.33' ' 0.429' ' 0.22' ' 0.1' ' 0.492' ' 0.1' ' 0.31' ' 0' ' 10' 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))

b = Columns 1 through 17 0.0336 0.1891 0.6223 0.6145 0.9529 0.3795 0.6833 0.8159 0.6108 0.2983 0.6012 0.5750 0.8629 0.9673 0.7300 0.9154 0.0291 Columns 18 through 34 0.1411 0.3473 0.9219 0.9074 0.3998 0.2248 0.0315 0.8476 0.7833 0.6839 0.4492 0.7387 0.1384 0.8769 0.4487 0.0614 0.7825 Columns 35 through 51 0.0215 0.5837 0.9142 0.0533 0.6428 0.6790 0.6034 0.7863 0.6757 0.4442 0.7658 0.0840 0.3134 0.6785 0.5282 0.7146 0.7845 Columns 52 through 68 0.7576 0.2387 0.8439 0.5334 0.3239 0.2294 0.7932 0.4671 0.2744 0.1395 0.4327 0.2774 0.7368 0.6417 0.9589 0.7531 0.9277 Columns 69 through 85 0.7476 0.5775 0.8490 0.7281 0.7754 0.2648 0.8805 0.3146 0.4602 0.6841 0.0811 0.8138 0.0481 0.9273 0.1696 0.6613 0.4484 Columns 86 through 100 0.0423 0.1050 0.8967 0.1916 0.3348 0.2156 0.1260 0.6269 0.3796 0.9316 0.9122 0.9963 0.0254 0.1185 0.9653 c = 101×7 char array ' 0.0336' '0.18914' '0.62226' '0.61447' '0.95289' ' 0.3795' '0.68333' '0.81589' '0.61084' '0.29829' '0.60124' '0.57496' '0.86294' '0.96727' '0.72997' '0.91536' '0.02915' '0.14105' '0.34727' '0.92187' '0.90744' '0.39979' '0.22477' '0.03148' ' 0.8476' '0.78326' '0.68393' '0.44917' '0.73873' '0.13837' '0.87687' '0.44869' '0.06137' '0.78254' '0.02146' '0.58371' '0.91418' '0.05327' '0.64283' '0.67899' '0.60341' '0.78625' '0.67567' '0.44417' '0.76575' '0.08398' '0.31337' ' 0.6785' '0.52818' ' 0.7146' '0.78453' '0.75757' '0.23869' '0.84387' '0.53337' '0.32389' '0.22943' '0.79319' '0.46705' '0.27442' '0.13949' '0.43267' '0.27738' '0.73675' '0.64173' ' 0.9589' '0.75306' '0.92769' '0.74758' '0.57749' '0.84901' '0.72811' '0.77545' '0.26483' '0.88052' '0.31462' '0.46024' '0.68411' '0.08107' '0.81381' '0.04812' '0.92725' '0.16959' '0.66127' '0.44839' '0.04227' '0.10501' '0.89672' '0.19158' '0.33482' '0.21559' '0.12598' '0.62692' '0.37963' '0.93164' '0.91222' '0.99634' '0.02544' '0.11851' '0.96529' ' 10' y = 5

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

b = Columns 1 through 17 0.2260 0.2797 0.3471 0.7614 0.7266 0.6024 0.5941 0.0910 0.2760 0.8864 0.1981 0.6857 0.9471 0.4814 0.6246 0.9139 0.7736 0.5876 0.9798 0.6883 0.4941 0.4746 0.1365 0.0281 0.5530 0.1382 0.7473 0.3830 0.7117 0.9507 0.3649 0.8293 0.1383 0.1984 0.9538 0.4601 0.9973 0.9179 0.3151 0.9138 0.5957 0.7468 0.3105 0.0209 0.4438 0.8513 0.0893 0.1417 0.3987 0.6885 0.3144 0.9772 0.3813 0.0366 0.2802 0.9185 0.5574 0.9554 0.4221 0.9986 0.8332 0.3937 0.1466 0.1068 0.6032 0.3880 0.2489 0.0411 0.4187 0.6644 0.4707 0.7508 0.5300 0.1209 0.5010 0.4292 0.1816 0.5551 0.9827 0.0968 0.4489 0.4348 0.0025 0.4902 0.5262 Columns 18 through 20 0.5947 0.4759 0.0236 0.7276 0.8256 0.1079 0.2891 0.1477 0.9164 0.0579 0.8718 0.6330 0.6668 0.3453 0.8565 c = 101×8 char array '0.226025' '0.587552' '0.953764' '0.977196' '0.418655' '0.279662' '0.979794' '0.460077' '0.381344' '0.664417' '0.347121' ' 0.68832' '0.997262' '0.036631' '0.470738' '0.761356' '0.494075' '0.917899' '0.280219' '0.750782' '0.726619' '0.474574' '0.315128' '0.918538' '0.530035' '0.602446' '0.136468' '0.913775' ' 0.55739' '0.120867' '0.594133' '0.028059' '0.595728' '0.955356' '0.500988' '0.091026' '0.552966' ' 0.74684' '0.422119' '0.429191' '0.276028' '0.138231' '0.310543' '0.998592' '0.181561' '0.886394' '0.747327' '0.020906' '0.833248' '0.555102' '0.198137' '0.383004' '0.443841' '0.393653' '0.982716' '0.685672' '0.711738' '0.851324' '0.146564' '0.096764' '0.947125' '0.950729' ' 0.08926' ' 0.10681' '0.448853' '0.481395' '0.364908' '0.141713' '0.603205' '0.434806' '0.624635' '0.829326' '0.398693' '0.387961' '0.002498' '0.913885' ' 0.13834' '0.688537' '0.248882' '0.490241' '0.773643' '0.198395' ' 0.31439' '0.041056' ' 0.52625' '0.594708' '0.727556' '0.289064' ' 0.05786' '0.666761' '0.475851' ' 0.82555' '0.147675' '0.871759' '0.345341' '0.023617' ' 0.10789' '0.916424' '0.633043' '0.856488' ' 10' y = 6

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

b = 0 c = 2×2 char array ' 0' '10' y = 0

### Community Treasure Hunt

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

Start Hunting!