Cody

Solution 1942863

Submitted on 19 Sep 2019 by Augusto Mazzei
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
A = [1 2 3 4 5 6]; C = [6 24 60 120]; assert(isequal(moveprod(A,3),C))

ans = 6 24 60 120

2   Pass
A = [1 2 3 4 5 6].'/6; C = [2 6 12 20 30].'/6^2; B = moveprod(A,2); assert(max(abs(B-C)) <= max(abs(C))*1e-12 && isequal(size(B),size(C)))

ans = 0.0556 0.1667 0.3333 0.5556 0.8333

3   Pass
A = [-1 4 3 6 -2 2 0 1 2 -3 3 -6 -2 3 5]; C = [-2 0 3 12 6 6 0 -2 6 -15]; assert(isequal(moveprod(A,2),C))

ans = -2 0 3 12 6 6 0 -2 6 -15

4   Pass
A = [-1 4 3 6 2 2 0 1 2 3 3 -6 -2 3 5]/pi; C = [-12 72 36 0 0 6 36 36 -30]/pi^3; B = moveprod(A,3,2); assert(max(abs(B(:) - C(:))) <= max(abs(C(:)))*1e-12 && isequal(size(B),size(C)))

ans = -0.3870 2.3221 1.1611 0 0 0.1935 1.1611 1.1611 -0.9675

5   Pass
A = randi([-10,10],10,10,100); k = 5; dim = 3; B = moveprod(A,k,dim); szA = size(A); C = zeros(szA(1),szA(2),szA(3)-k+1); for m = 1:szA(1) for n = 1:szA(2) C(m,n,:) = moveprod(squeeze(A(m,n,:)),k); end end assert(isequal(B,C))

ans(:,:,1) = 0 750 19440 -2592 48 0 0 0 9450 0 -18900 14175 -450 0 0 17280 -180 -10000 -560 0 3200 6400 7200 1512 0 0 -504 -1440 960 2700 -3500 0 -324 2240 1764 -1296 -5760 640 384 4800 0 17010 -1800 9800 -20160 -1792 0 -2400 0 -3600 -1440 378 0 15120 -16128 0 5880 0 10500 -210 0 1296 -432 0 -4900 1296 10080 10752 0 0 4500 -5600 -5040 1440 -1296 0 2160 -756 -480 0 9072 0 162 -2160 -90 0 2304 9000 -216 -480 1920 -243 480 0 -1944 0 -17010 -1125 0 756 ans(:,:,2) = 0 -250 3888 2304 72 0 0 0 8400 0 -13230 -28350 180 0 0 3840 100 6000 1680 0 12800 5120 4320 -945 0 0 -72 -3600 576 0 -1400 0 1620 560 756 324 -6480 -128 -1728 6000 0 5670 5400 9800 -5040 2688 0 -6000 0 -2800 576 84 0 -6480 -2688 96 3920 108 14700 -350 0 -5184 144 0 -4200 -1944 -8400 -2688 0 0 3600 -4800 504 -3360 864 0 2160 0 240 0 12096 0 648 -1080 630 7200 -3456 -22500 -1728 720 -2688 -810 -1920 -630 -1620 0 -5103 3750 0 3402 ans(:,:,3) = 0 100 3456 -576 0 336 0 -900 16800 0 10290 0 -900 0 0 -1440 -800 -6750 720 0 5120 1920 -4320 9450 0 0 0 5400 576 0 0 0 540 1120 6804 864 -5184 48 -1296 15000 -120 1134 -3000 -7000 -2880 -672 0 4200 2240 -8400 2880 -672 1620 2160 -1792 -224 -5040 -324 -4410 -875 0 -6912 -180 0 0 -3402 -2100 -672 0 0 -1440 -8400 -504 -15120 864 0 2700 0 -336 0 -20160 0 1944 -108 -420 6000 -5184 10000 4320 720 2016 -4860 -768 5670 -2430 0 -4536 0 0 -2916 ans(:,:,4) = 0 0 -2304 2304 0 -672 0 -180 8400 0 -13230 0 -900 0 0 576 -1600 -8100 900 0 512 0 -3360 -12600 0 -12960 0 -6750 -432 0 0 0 -2430 320 -5670 1440 -11664 192 -1944 0 -480 -756 1800 7000 0 6048 2100 18900 1344 -7560 -960 768 -1080 -1440 672 56 -720 1620 -7350 -1125 0 -6912 -120 23814 0 6804 -350 0 0 0 -240 -33600 -504 -6048 3456 0 6300 0 -378 0 -11520 -24500 972 189 420 -13500 6048 2000 8640 -1260 -6048 4320 96 -15120 -9720 0 3528 0 0 4860 ans(:,:,5) = 0 0 512 576 0 -384 0 -450 -6000 0 -17640 0 1080 0 0 -1344 -3200 -6480 720 0 1024 0 1680 1400 0 32400 0 0 -576 0 0 0 -21870 400 945 960 -11664 24 972 0 480 216 1440 0 0 4536 1680 -18900 8064 -37800 -240 -256 -2880 0 864 126 -900 -720 0 -1350 -31752 15552 360 -7938 0 -11340 -500 0 0 12096 -160 16800 144 -3780 -2304 0 -11340 0 504 -5760 -3840 24500 540 1512 -210 -18900 -7560 1800 -960 1050 15120 -1920 96 10080 5400 0 1512 0 0 -34020 ans(:,:,6) = -1080 0 -576 -256 0 -288 -7560 -300 -7200 -1920 -5292 0 -1800 0 -2304 1008 1920 -3888 6480 3528 1152 0 -336 -400 0 -10800 0 0 4032 0 0 0 9720 400 540 -3360 9720 12 4860 0 288 -252 2160 0 0 -1296 -1680 -18900 -3456 7560 -240 768 -3840 0 864 -378 1440 960 0 13500 36288 0 2520 -7938 0 6300 800 0 1008 -30240 -192 0 288 5040 -6912 3840 5670 0 2268 7200 0 49000 -1440 -1680 -252 -15750 -1890 -720 -960 -10500 9450 19200 -192 -14400 -9000 1120 1512 0 2880 26460 ans(:,:,7) = 432 0 -1440 -256 0 -720 6480 -360 -4500 -960 -7560 0 1800 14400 -576 3528 3840 3888 -15120 -21168 2592 0 168 -400 0 12600 0 0 4032 -2268 0 0 -2916 1200 900 -15120 -4320 72 -1080 0 48 336 -1440 0 0 1296 -2800 30240 -4320 0 420 -768 6144 0 -1728 2268 -3600 -4800 0 13500 -36288 0 -5040 -2268 0 5600 1120 0 -432 5040 0 0 1152 -5040 1152 7680 -11340 1680 -13608 7200 0 56000 -2160 -560 0 0 630 288 480 -10500 -4050 5760 48 -25920 9000 -672 -1512 0 2160 8820 ans(:,:,8) = -720 0 0 -256 3600 -720 -4860 360 1800 -1600 -3240 0 0 12960 2304 2352 -480 2160 30240 -21168 -1296 0 147 400 0 -2100 21504 0 3024 4536 0 0 -5832 2700 600 -13230 -8640 72 1080 0 -72 336 -1152 0 0 1944 0 -17280 -7560 0 0 96 -2048 0 -4320 2268 4000 3200 0 5400 -20736 0 1008 0 -8000 2400 5600 0 756 2880 0 0 -960 -5600 1152 -4800 7938 560 -9720 5400 0 -56000 -960 1680 0 0 1050 720 96 -16800 -675 0 -240 2880 10000 -504 -1512 11520 -1920 -5880 ans(:,:,9) = 3240 -6750 0 192 -28800 -360 -4860 3600 -2400 4000 -1440 0 0 0 2...

6   Pass
A = 20*rand(10,10,100)-10; k = 4; dim = 3; B = moveprod(A,k,dim); szA = size(A); C = zeros(szA(1),szA(2),szA(3)-k+1); for m = 1:szA(1) for n = 1:szA(2) C(m,n,:) = moveprod(squeeze(A(m,n,:)),k); end end C = C + 100*eps(C); assert(max(abs(B(:) - C(:))) <= max(abs(C(:)))*1e-12 && isequal(size(B),size(C)))

ans(:,:,1) = 1.0e+03 * 0.0624 -0.0670 -0.5013 2.3005 -0.8671 -0.1595 -0.0127 -0.5145 -1.2056 -0.1883 0.1323 0.0632 0.0047 0.0332 1.4829 0.3671 0.7052 3.2052 -0.0788 -0.0104 3.0903 0.0077 -0.2371 -0.0084 -0.0636 -0.1634 -0.0121 0.3336 0.2234 -1.2755 -0.4006 0.2558 -0.6765 0.0624 -0.0359 -0.0239 0.0124 -0.0665 0.0981 -0.1282 0.1429 -0.0420 0.1645 0.4390 0.2152 1.7079 -0.1899 0.1344 0.0140 0.6089 0.1548 0.0006 -0.0067 0.0732 -0.1059 2.3946 0.2137 0.5474 -2.7756 -0.5752 0.0031 0.0378 -0.4144 0.2440 -3.1768 -0.2626 0.6872 -0.0129 -0.1815 0.0086 0.6825 1.4316 -0.2526 1.4461 -0.0204 -0.0435 -1.1457 -0.1838 -0.1234 -0.0560 0.1038 0.0387 -0.0929 0.6804 -1.6987 -0.0066 -0.0004 0.0000 0.1952 -0.2105 0.2888 -0.0062 0.1473 2.6367 1.6652 0.2135 0.0917 0.1989 1.7885 -0.2530 ans(:,:,2) = 1.0e+03 * -0.0527 -0.1294 -1.3873 2.7891 -1.7893 -0.4006 0.0833 0.0637 0.5134 0.1349 0.0533 -0.1346 -0.0344 0.6380 1.9952 0.2897 2.0759 -0.4928 -0.0057 -0.0162 -2.5195 0.0049 -1.7766 0.0590 0.7250 0.0390 0.0469 -0.5572 0.2959 -2.0267 -0.4517 -0.2198 1.4547 -0.0538 -0.7532 -0.0146 0.0767 -0.0150 -0.2028 -0.3361 -0.0185 -0.1654 -0.0907 -0.3736 -0.4450 -1.5976 -0.7300 -0.0957 -0.0153 -0.1243 0.0152 -0.0331 0.0091 0.3141 0.1619 -2.8410 0.3389 -0.1206 3.2485 0.2591 -0.0190 -0.0557 0.3276 0.3548 -4.9096 3.2940 0.5550 -0.0056 -0.2527 -0.2726 0.0080 1.1930 0.4350 -0.7825 0.0259 0.0517 0.8293 0.4835 -0.8627 0.0316 0.8133 -0.1058 -0.0065 0.4997 -1.1763 -0.0090 -0.0047 0.0012 0.4495 0.1883 0.3140 -0.0491 0.2060 2.1840 1.1973 -0.1162 -0.4249 0.9174 1.3634 -0.0394 ans(:,:,3) = 1.0e+03 * -0.0109 -0.2240 1.0539 -0.4919 1.7375 0.0388 -0.3039 -0.0458 0.3700 -0.0103 -0.0032 0.0626 -0.0303 0.3649 2.1109 0.1081 1.6765 -0.3227 -0.0150 -0.1947 2.2914 -0.0597 -1.3168 -0.0463 0.3033 0.0400 -0.0465 -3.8537 0.1981 0.0840 -2.1786 -0.0135 -1.4521 -0.1726 -0.3471 -0.0683 0.0210 0.0204 0.1449 -0.1875 -0.0371 0.3759 -0.0150 -0.2983 -1.4275 1.3295 -1.3817 0.0072 -0.0494 0.0114 0.0456 -0.0199 -0.2364 0.2681 -0.4236 4.2383 0.2331 0.2035 3.5585 -0.3411 0.0161 -0.4633 -0.0895 -0.0664 2.9727 -4.8496 0.5175 -0.1237 -0.2051 0.2285 0.0304 -3.2574 -0.4542 0.5282 -0.0131 -0.0247 0.3041 1.5176 -1.0236 0.1511 0.5308 0.6673 -0.2054 -0.8789 -1.2256 0.0553 0.0006 0.0658 0.4957 -0.3873 0.2763 -0.3242 0.0612 -0.9448 -0.2585 0.1201 0.5216 -0.7122 0.4475 0.0392 ans(:,:,4) = 1.0e+03 * -0.0093 0.2253 1.2601 -0.5830 0.4615 -0.0401 0.2904 -0.0775 -0.0044 -0.0041 -0.0095 -0.0894 -0.0162 -0.6459 -4.6354 -0.2999 1.4628 -0.5680 0.1275 -0.1223 -2.4835 0.1107 -0.0645 -0.0910 -0.5747 -0.0581 -0.0552 -3.6072 -0.3594 -0.0819 0.9990 0.0003 4.3706 0.7592 -0.0383 -0.0020 0.0020 -0.0140 0.1382 -0.2499 0.0615 -1.1465 -0.0159 0.0845 2.4367 -1.7053 1.0118 -0.0055 0.0837 -0.0092 0.5100 -0.1564 -0.0147 0.2436 0.0445 -4.4598 -0.8106 -0.2586 0.1543 -0.3864 -0.0234 -0.6432 -0.1278 0.0673 -2.0767 -1.8467 1.2333 -0.3703 -0.3227 -0.4235 -0.0084 0.8015 0.2216 0.7229 0.0073 0.0715 0.0064 0.8831 1.6481 -0.0390 1.0341 0.2745 0.2839 1.6816 1.2474 1.6976 0.0004 -0.0577 -0.7294 -0.1099 0.1807 -0.4688 0.0137 2.0079 0.0290 0.1817 1.7508 1.0700 0.2496 -0.0670 ans(:,:,5) = 1.0e+03 * -0.2112 -1.0884 -0.9858 0.0259 -0.4733 0.0358 -0.2143 -0.0226 -0.0013 0.0141 0.0085 -0.0565 -0.0414 -2.9579 4.1949 -0.0829 1.0621 0.5708 0.0448 1.3057 -1.1209 1.0573 0.0281 0.0783 -0.5488 -0.6346 -0.0449 5.4807 -0.6591 -0.1395 -0.6341 0.0011 1.9135 0.0159 -0.2822 0.0230 0.0191 -0.2393 -0.1939 -0.3993 0.0927 -6.8464 -0.0060 0.1471 -1.2653 2.6542 2.9871 0.0017 0.7926 0.0164 -0.3591 -0.0630 -0.0273 -0.2343 0.0600 -3.2311 0.8810 0.2147 -0.0367 -0.6529 -1.4111 -0.8663 -0.4109 0.0261 0.6217 0.2183 -1.1754 -0.1247 1.0958 -0.5316 -0.0107 -0.2464 -0.3788 -1.2102 -0.2207 -0.0402 0.0155 0.5007 3.0839 -0.0812 -2.3622 0.0726 0.0542 0.4483 0.7636 0.8836 -0.0208 0.4930 -3.1373 0.0121 0.1594 0.2177 -0.0472 0.8017 0.0212 -0.2587 1.7789 -0.2513 0.0805 0.3015 ans(:,:,6) = 1.0e+03 * 0.0941 0.9347 0.9992 -0.0168 -1.3686 -0.0927 0.1004 0.1140 0.0007 -0.0019 -0.1039 0.0309 -0.2243 2.3545 -2.1563 -0.0470 -0.4808 1.6048 -1.2353 0.2452 -0.2803 -1.3349 -0.0287 -0.4066 0.5754 -2.9733 0.0367 5.9885 0.1465 -0.1206 0.8877 0.0017 -0.1935 -0.0017 -0.0155 -0.0549 0.1060 0.6507 -0.8014 0.6149 1.3845 -4.9425 -0.0084 0.4345 0.3191 -0.4687 -2.4913 -0.0011 0.3403 -0.0595 1.4733 0.1002 -0.0360 0.4627 -0.0119 0.4584 1.0389 -0.1137 -0.0120 3.7359 1.4780 1.0284 -0.3689 -0.0073 0.5540 -0.0289 0.3270 0.0307 -1.3107 -0.0411 -0.6445 0.0114 0.0423 0.5348 0.3178 0.0821 0.0259 0.2268 1.5679 0.2550 -0.8990 -0.0308 -0.3172 -0.6569 -0.0373 0.0429 0.0593 0.3406 -0.0902 -0.0506 0.4472 0.1163 0.0229 -0.3751 0.0152 0.2505 -1.1756 -0.1191 -0.0386 -1.7729 ans(:,:,7) = 1.0e+03 * -0.3039 -2.5552 -1.0492 0.0354 0.4443 -0.1092 0.0025 -0.0628 -0.0011 0.0219 -0.9798 -0.0454 -0.2821 2.7191 1.3633 0.1659 1.4074 2.0423 0.5791 -0.3680 -0.3085 1.0492 0.0106 -0.3753 0.9207 2.0946 -0.0300 5.6071 0.3729 -1.8884 -0.2586 -0.0059 0.1165 0.0003 -0.0322 -0.0075 0.2059 0.2366 -1.3128 0.4075 -0.5384 4.7833 -0.0034 0.6672 0.0744 -0.4544 0.8085 0.0079 0.4609 -0.4292 -1.3461 -0.3129 -0.0038 1.5978 -0.0212 -0.1816 -0.7062 -0.1250 -0.0124 2.5034 -1.2988 -1.0446 0.4634 0.0029 0.1845 0.0250 -0.6821 0.0276 -0.4398 0.0170 -0.4187 -0.0103 -0.0205 1.3306 0.0692 0.3383 -0.0553 0.3300 2.1804 -0.7919 0.0265 0.0129 -0.3396 -0.3884 -0.0288 0.0001 -0.1869 -0.3532 -0.0013 0.1358 -0.6790 0.0575 -0.0496 0.8054 -0.0804 -0.0546 2.0668 -0.1765 0.0266 -1.7250 ans(:,:,8) = 1.0e+03 * -0.7750 0.2287 -1.1391 -0.0379 -1.7921 0.1120 -0.0014 0.1453 0.1333 0.0258 1.6638 -0.0119 -0.3500 -0.1085 -0.5780 0.0239 1.5249 -2.1494 -0.5053 -0.1407 -0.0026 0.7173 -0.1700 0.1278 -2.0792 -0.6269 0.0324 -5.1863 0.4829 0.2459 0.6801 -0.0881 0.0263 0.0007 -0.1690 -0.4487 -1.3273 0.1122 1.1618 -0.4179 -0.7179 -2.6364 0.0021 -2.3516 -0.0779 0.0939 -1.1382 -0.0024 -0.4555 -0.4767 -0.3446 0.4920 0.0072 -3.2977 -0.0036 0.0881 0.6089 0.2252 0.2088 1.5866 -1.8678 -0.9876 0.0269 0.0182 0.1580 0.0335 -0.5679 0.0131 -0.1525 0.0202 -2.1234 0.0139 0.0422 0.0839 0.1971 -0.0303 2.3711 -0.2563 -0.5843 -2.7798 0.0034 0.0113 0.3498 0.0487 -0.0093 0.0002 -0.3212 -0.3927 0.0005 0.1303 -0.6957 -0.0042 0.0606 0.8812 -0.1636 -0.1232 -2.0498 0.1687 0.0228 -5.2791 ans(:,:,9) = 1.0e+03 * -0.3332 -0.1306 -0.2565 -0.4180 1.5014 -0.0530 0.0012 -0.3700 0.6491 0.0186 -1.0088 0.0123 -0.5326 -0.1090 -0.1364 -0.0156 0.9002 1.0125 1.2500 -0.1653 -0.0076 -0.7830 -1.1179 0.4677 -1.4716 -0.1579 -0.0465 0.6174 0.6884 -0.2301 0.5227 0.1222 0.0371 -0.0215 0.0887 -0.1599 -1.9193 0.4139 0.2257 0.0437 -1.2663 1.1633 0.0138 2.0928 0.1064 -0.1072 -0.6602 -0.0064 0.0135 0.3523 0.3219 -1.3189 0.0041 3.5686 0.0033 0.0095 -0.4653 -0.1999 0.1563 0.4804 1.9314 1.4423 0.0003 -0.0306 -0.4301 -0.3042 0.2798 -0.0117 -0.2657 0.0500 -0.0486 0.0146 -0.0623 0.0527 0.0957 -0.0333 2.4629 1.3121 -0.0282 0.5782 -0.0033 0.0084 0.7567 -0.2113 -0.0080 -0.0001 -1.3213 1.9027 -0.0002 -0.4357 -0.0588 0.0086 0.0297 -0.5251 -0.0211 0.0423 2.3172 -0.3359 0.1968 -3.6878 ans(:,:,10) = 1.0e+03 * 0.9568 -0.0130 -0.1469 0.9063 1.5567 -0.0383 -0.0011 -0.5909 -1.4636 0.0633 -0.9710 -0.0571 -0.0012 0.1302 0.1283 0.0180 0.8473 -1.7358 -0.3309 0.0193 0.0049 0.2995 -0.2079 -0.2651 -1.1194 0.0910 -0.0985 -0.6227 1.3231 -0.2964 -0.2025 -0.1048 -0.0557 -0.1209 -1.7602 0.0069 -0.6247 0.5000 0.3301 0.0319 0.0586 1.0187 -0.0282 0.2938 0.1026 -0.2263 -0.7600 -0.0292 -0.0182 0.4072 -0.5847 0.3526 -0.0034 -1.8485 -0.0008 -0.0602 -0.0204 0.7445 0.0560 0.0465 -1...