Cody

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

Solution 3358603

Submitted on 24 Oct 2020 by Giovanni Mottola
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))

n = 0 d = 1 y = 1 1 0 10 2 2 4 1000 5 6 7 8 n = 1 d = 10 y = 1.0e+03 * 0.0010 0.0010 0.0002 0.0101 0.0021 0.0023 0.0041 1.0003 0.0050 0.0064 0.0075 0.0080 n = 2 d = 100 y = 1.0e+03 * 0.0010 0.0010 0.0002 0.0101 0.0020 0.0023 0.0041 1.0003 0.0050 0.0064 0.0075 0.0080 n = 3 d = 1000 y = 1.0e+03 * 0.0010 0.0010 0.0002 0.0101 0.0020 0.0023 0.0041 1.0003 0.0050 0.0064 0.0075 0.0080 n = 4 d = 10000 y = 1.0e+03 * 0.0010 0.0010 0.0002 0.0101 0.0020 0.0023 0.0041 1.0003 0.0050 0.0064 0.0075 0.0080

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

n = 0 d = 1 y = Columns 1 through 29 0 1 1 1 1 1 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1 0 1 1 1 Columns 30 through 58 0 1 0 1 1 1 1 1 0 1 0 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 0 1 1 Columns 59 through 87 0 1 1 1 1 1 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 1 0 1 Columns 88 through 100 0 0 0 0 1 0 0 0 1 1 1 0 1 n = 1 d = 10 y = Columns 1 through 17 0.5000 0.8000 0.7000 0.6000 0.5000 0.7000 0.4000 0.2000 0.2000 0.8000 0.6000 0.7000 0.2000 0.1000 0.6000 0.8000 0.8000 Columns 18 through 34 0.5000 0.7000 0.8000 0.9000 0.1000 0.5000 0 0.7000 0.3000 0.6000 0.7000 0.7000 0.2000 0.8000 0.1000 0.8000 0.8000 Columns 35 through 51 0.5000 0.5000 0.7000 0.2000 0.8000 0.4000 0.1000 0.9000 0 0.8000 0.3000 0.6000 0.6000 0.6000 0.5000 0 1.0000 Columns 52 through 68 0.6000 0.9000 0.6000 1.0000 0 0.6000 0.7000 0.1000 0.8000 0.9000 0.9000 0.6000 0.7000 0.4000 0.8000 0.7000 0.5000 Columns 69 through 85 0.8000 0.3000 0.1000 0.6000 0.5000 0.1000 0.9000 0.1000 0.2000 0.7000 0.7000 0.9000 0.4000 0.8000 0.8000 0.4000 0.9000 Columns 86 through 100 0.2000 0.7000 0.3000 0.5000 0.3000 0.5000 0.8000 0.3000 0.2000 0.4000 0.8000 0.9000 0.6000 0.3000 0.6000 n = 2 d = 100 y = Columns 1 through 17 0.4800 0.8000 0.7000 0.5800 0.5100 0.7300 0.4400 0.2400 0.1800 0.8300 0.6300 0.6700 0.1800 0.0600 0.6400 0.7900 0.7600 Columns 18 through 34 0.4600 0.6700 0.7900 0.8900 0.0700 0.4700 0.0500 0.7000 0.2900 0.6000 0.7200 0.7200 0.2300 0.8300 0.0500 0.8100 0.7500 Columns 35 through 51 0.5500 0.5500 0.6500 0.2500 0.7900 0.3600 0.1200 0.9200 0.0100 0.7900 0.3300 0.6100 0.5500 0.6400 0.5100 0.0400 0.9600 Columns 52 through 68 0.5700 0.8700 0.5900 0.9700 0.0400 0.5700 0.7100 0.1300 0.8300 0.9000 0.9200 0.5900 0.6900 0.3700 0.7600 0.7500 0.4700 Columns 69 through 85 0.8300 0.3300 0.1300 0.6100 0.5400 0.1400 0.8700 0.1300 0.1600 0.6800 0.6700 0.9100 0.3900 0.8200 0.7800 0.4300 0.8600 Columns 86 through 100 0.2400 0.6900 0.2800 0.4900 0.2700 0.5000 0.7600 0.3000 0.1700 0.3900 0.8400 0.8800 0.6000 0.3300 0.6400 n = 3 d = 1000 y = Columns 1 through 17 0.4790 0.7950 0.7000 0.5790 0.5120 0.7340 0.4350 0.2360 0.1780 0.8280 0.6280 0.6740 0.1800 0.0560 0.6440 0.7950 0.7600 Columns 18 through 34 0.4620 0.6670 0.7940 0.8920 0.0690 0.4730 0.0470 0.7030 0.2850 0.6030 0.7170 0.7200 0.2290 0.8330 0.0510 0.8100 0.7550 Columns 35 through 51 0.5490 0.5460 0.6540 0.2480 0.7930 0.3610 0.1180 0.9230 0.0090 0.7920 0.3280 0.6060 0.5550 0.6360 0.5130 0.0440 0.9600 Columns 52 through 68 0.5750 0.8660 0.5890 0.9730 0.0440 0.5650 0.7060 0.1290 0.8310 0.9000 0.9210 0.5940 0.6910 0.3720 0.7640 0.7450 0.4740 Columns 69 through 85 0.8320 0.3320 0.1350 0.6110 0.5420 0.1380 0.8710 0.1290 0.1570 0.6800 0.6710 0.9110 0.3890 0.8210 0.7770 0.4260 0.8600 Columns 86 through 100 0.2430 0.6880 0.2780 0.4930 0.2660 0.5000 0.7610 0.3020 0.1660 0.3910 0.8440 0.8780 0.6030 0.3250 0.6410 n = 4 d = 10000 y = Columns 1 through 17 0.4787 0.7955 0.7000 0.5785 0.5119 0.7341 0.4353 0.2360 0.1777 0.8278 0.6280 0.6736 0.1797 0.0555 0.6444 0.7948 0.7602 Columns 18 through 34 0.4620 0.6666 0.7944 0.8921 0.0693 0.4729 0.0471 0.7025 0.2854 0.6028 0.7169 0.7205 0.2292 0.8333 0.0511 0.8098 0.7545 Columns 35 through 51 0.5490 0.5461 0.6536 0.2482 0.7928 0.3615 0.1177 0.9225 0.0090 0.7916 0.3278 0.6060 0.5549 0.6361 0.5125 0.0435 0.9601 Columns 52 through 68 0.5747 0.8657 0.5893 0.9731 0.0436 0.5653 0.7062 0.1288 0.8307 0.9004 0.9212 0.5938 0.6907 0.3723 0.7642 0.7453 0.4737 Columns 69 through 85 0.8321 0.3318 0.1346 0.6109 0.5422 0.1377 0.8705 0.1289 0.1567 0.6805 0.6715 0.9111 0.3890 0.8212 0.7769 0.4260 0.8596 Columns 86 through 100 0.2427 0.6879 0.2780 0.4934 0.2664 0.4999 0.7607 0.3018 0.1657 0.3910 0.8444 0.8784 0.6033 0.3252 0.6409 n = 5 d = 100000 y = Columns 1 through 17 0.4787 0.7955 0.7000 0.5785 0.5119 0.7341 0.4354 0.2360 0.1777 0.8278 0.6280 0.6736 0.1797 0.0555 0.6444 0.7948 0.7602 Columns 18 through 34 0.4620 0.6665 0.7944 0.8921 0.0693 0.4729 0.0471 0.7025 0.2854 0.6028 0.7169 0.7205 0.2292 0.8333 0.0511 0.8098 0.7545 Columns 35 through 51 0.5490 0.5461 0.6536 0.2482 0.7928 0.3615 0.1177 0.9225 0.0090 0.7916 0.3278 0.6060 0.5549 0.6361 0.5125 0.0435 0.9601 Columns 52 through 68 0.5747 0.8657 0.5893 0.9731 0.0436 0.5653 0.7062 0.1288 0.8307 0.9004 0.9212 0.5938 0.6907 0.3723 0.7642 0.7453 0.4737 Columns 69 through 85 0.8321 0.3318 0.1346 0.6109 0.5422 0.1377 0.8705 0.1289 0.1567 0.6805 0.6715 0.9111 0.3890 0.8212 0.7769 0.4260 0.8596 Columns 86 through 100 0.2427 0.6879 0.2780 0.4934 0.2664 0.4999 0.7607 0.3018 0.1657 0.3910 0.8444 0.8784 0.6034 0.3252 0.6409 n = 6 d = 1000000 y = Columns 1 through 17 0.4787 0.7955 0.7000 0.5785 0.5119 0.7341 0.4353 0.2360 0.1777 0.8278 0.6280 0.6736 0.1797 0.0555 0.6444 0.7948 0.7602 Columns 18 through 34 0.4620 0.6666 0.7944 0.8921 0.0693 0.4729 0.0471 0.7025 0.2854 0.6028 0.7169 0.7205 0.2292 0.8333 0.0511 0.8098 0.7545 Columns 35 through 51 0.5490 0.5461 0.6536 0.2482 0.7928 0.3615 0.1177 0.9225 0.0090 0.7916 0.3278 0.6060 0.5549 0.6361 0.5125 0.0435 0.9601 Columns 52 through 68 0.5747 0.8657 0.5893 0.9731 0.0436 0.5653 0.7062 0.1288 0.8307 0.9004 0.9212 0.5938 0.6907 0.3723 0.7642 0.7453 0.4737 Columns 69 through 85 0.8321 0.3318 0.1346 0.6109 0.5422 0.1377 0.8705 0.1289 0.1567 0.6805 0.6715 0.9111 0.3890 0.8212 0.7769 0.4260 0.8596 Columns 86 through 100 0.2427 0.6879 0.2780 0.4934 0.2664 0.4999 0.7607 0.3018 0.1657 0.3910 0.8444 0.8784 0.6033 0.3252 0.6409

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

n = 0 d = 1 y = 0 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 1 1 0 1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 0 0 0 0 1 0 0 1 0 0 n = 1 d = 10 y = Columns 1 through 17 0.1000 0.9000 0.8000 0.3000 0.2000 0.7000 1.0000 0 0.7000 0.4000 0.2000 0.3000 0.1000 0.4000 0.3000 0.4000 0.1000 0.4000 0.8000 0.7000 0.2000 0.1000 0.3000 0.4000 0.5000 1.0000 0.4000 0.3000 0.1000 0.5000 0.8000 0.1000 0.7000 0.1000 0.8000 0.5000 0.6000 0.1000 0.2000 0.5000 0.6000 1.0000 0.6000 0.8000 0.9000 0.2000 0.4000 0.3000 0.8000 0.1000 0.1000 0.9000 0.3000 0.2000 0.7000 0.1000 0.9000 0.4000 0.7000 0.3000 1.0000 0.8000 0.9000 0.3000 0.5000 0.9000 0.5000 0.3000 0.2000 0.6000 0.6000 0.3000 0.2000 0.7000 0.5000 0.1000 0.2000 0.7000 0.2000 0.2000 0.4000 0.1000 0.5000 0.2000 0.2000 Columns 18 through 20 0.3000 0.4000 0.4000 0 0.9000 0.8000 0.7000 0.4000 0.9000 0 0.5000 0.3000 0.9000 0 0.3000

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

n = 0 d = 1 y = 1

### Community Treasure Hunt

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

Start Hunting!