Cody

Solution 1314205

Submitted on 25 Oct 2017 by Jean-Marie Sainthillier
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 0 600 -1600 0 -81 -18900 3780 0 300 0 1620 24 0 5670 -2240 5040 320 480 0 -6174 -400 4500 0 1800 0 -1024 168 -120 112 -14400 -7000 0 8100 672 630 -7000 5040 -2240 0 4320 -576 -3240 -735 -10000 1728 -81 -2304 2100 360 13824 -189 -126 -1080 0 900 1000 -2016 -1296 0 -1440 16200 960 0 0 -2520 -1620 0 -10500 2520 -9408 7000 -700 6174 -700 -324 90 -6480 5120 -8640 -384 -12096 9408 5376 0 -30720 0 -1296 1120 0 -1200 22680 0 13440 12096 0 4200 1680 -3240 29160 ans(:,:,2) = 0 0 -5400 200 0 -162 13230 -1080 0 1050 -9600 2160 96 0 -3240 -280 720 -800 240 0 -882 160 3150 0 -2400 34560 0 -1008 600 -560 -28800 -5250 972 -9450 -672 882 9000 -5670 8960 0 864 144 4320 210 8000 2304 -648 -4608 3150 -840 -10368 168 126 -1440 -1920 1080 0 -3528 1296 0 3240 -27000 4800 0 0 2800 -2700 108 6000 -5670 13440 11200 -2450 -2646 1050 216 -72 -2880 3200 9720 864 4032 13440 4704 0 15360 0 -3888 560 0 1200 12960 0 10080 0 0 2940 16800 -8100 24300 ans(:,:,3) = 1280 240 -5400 -200 0 162 -9450 1080 0 1050 0 1080 672 0 -3240 400 576 -4000 -336 0 441 0 -2520 3456 2400 13824 0 -288 600 -980 28800 -9450 -2592 3150 -1792 -252 8100 6804 -10080 0 576 720 -14400 210 6400 288 1944 -5376 6300 -840 25920 72 42 -5760 640 -9720 0 -5040 -486 0 1080 12000 -4200 0 0 1400 -10800 864 600 7290 26880 4800 -6125 -1470 -1890 -360 -72 -2304 -800 -15552 432 -9072 -20160 5880 0 -11520 0 -6480 480 11520 4800 0 -2160 -3780 0 0 980 -16800 7200 10800 ans(:,:,4) = 800 -480 -16200 -200 0 -90 1575 -1890 0 1890 0 -540 -224 0 3600 400 -72 32000 336 -1440 378 0 -5040 -4608 4800 11520 0 0 900 1260 28800 -5670 1296 -5040 2304 1764 -16200 -4536 -6048 -2016 72 -600 -11520 -294 640 324 3240 10752 -5040 2100 8640 96 0 0 -896 -15552 0 20160 -324 0 -1728 -16000 -1050 0 -126 -2450 -7560 -3456 -840 -9720 -20160 -6720 4900 -1680 -567 -900 72 512 1600 13824 4320 -2268 -11520 3675 0 -10080 0 0 -192 46080 5760 0 -360 -540 0 0 -1400 -39200 -19200 16200 ans(:,:,5) = -4000 -576 -11340 -80 0 300 -350 630 0 -5670 0 4860 -1792 16800 -18000 -1400 24 -16000 -336 -1296 378 0 -7056 -4608 0 10080 0 0 450 5040 -4800 7938 432 1680 -2592 -1764 -12960 12096 -1728 -12096 24 400 -38400 1176 768 1620 -1800 18816 5760 2800 12960 288 0 0 784 1728 0 -17920 486 0 1728 0 735 5760 -126 -7350 12600 2880 336 -12960 -20160 1344 6300 -960 4536 0 -504 -2304 1920 -36864 -1440 -252 2880 -11025 -1600 8064 -1440 0 -72 -17280 -960 0 -108 -450 0 0 -700 23520 -3200 4860 ans(:,:,6) = -2400 -5184 6804 40 -18144 2100 -630 -882 0 -5670 0 3780 -2688 -4200 25200 4200 -8 12000 3360 -5832 420 0 784 -1536 0 2520 0 0 -2250 -17640 -7200 7938 648 1008 5184 3528 -6480 -10368 648 -27216 -48 900 12800 -1176 192 1260 7200 11760 4032 0 -1620 2016 0 0 882 3024 0 20160 486 0 1728 0 980 4032 189 9450 -12600 -4800 -896 20736 -22680 3360 3780 -3840 4536 0 -4536 -5184 0 32256 7200 144 -720 14175 -16000 3024 1440 0 -504 1920 576 0 486 450 0 0 0 -5880 -2880 3780 ans(:,:,7) = -1200 23328 -7560 -160 9072 9450 540 -882 -384 4860 0 -9450 4704 -2940 -31500 -21000 -16 -9600 -6720 -1944 -1680 0 1120 -1024 0 1400 -1470 0 2700 -3528 -720 23814 -720 1296 0 -504 1440 -10368 162 -15552 192 -1800 -14400 -4704 -24 1575 8100 -7350 -896 0 -2700 1512 0 0 -441 4536 864 -2880 108 0 768 0 -196 -4032 1701 -4725 -20160 -4800 448 -20736 13608 3360 -1620 8960 6048 0 -7938 -11664 0 -10752 -6400 -288 720 -2025 -32000 -8064 1800 0 0 0 -288 0 -243 1350 0 0 0 5880 -4608 -756 ans(:,:,8) = -9600 -20412 7560 64 9072 -3150 -324 2352 -288 -1620 1500 9450 -5376 -2058 -28000 -12600 -32 -1920 3840 -4860 6720 0 1960 -128 0 -1750 -2940 0 -1620 -2520 648 0 -630 -9072 0 2268 -320 -8640 144 19440 -192 -1620 -11520 0 24 1575 4500 -8400 -2240 0 -270 -3528 0 0 0 -1008 2160 -1728 144 -11520 768 0 0 -672 1215 -9450 -10080 3600 4032 0 -20412 8960 2268 -8960 6720 0 7938 -2916 0 -1344 9600 -96 320 2835 40000 13440 450 0 0 0 180 1200 567 -3150 0 0 0 840 1152 1890 ans(:,:,9) = 15360 17010 3780 640 -2016 -3150 324 -672 0 720 2700 7560 5376 2401 14...

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 * -1.9156 0.9830 -0.0019 -0.8240 0.7942 -0.0065 2.8031 0.6059 -0.4797 -0.1197 -0.3500 0.1198 -0.3953 2.6620 0.4840 -0.0623 0.0386 -0.0075 -2.7190 3.3900 -0.0506 0.0818 -0.0061 0.1043 -0.0158 -0.4082 0.0442 0.1007 0.0039 -0.5793 0.1254 -0.0705 -0.0000 0.6616 1.3211 -1.4070 0.0307 0.0368 -0.6337 -0.0074 -0.0104 1.0155 -2.5784 1.1094 -1.2694 0.7423 0.7096 1.6012 0.0719 0.7196 1.0972 0.0511 -0.9206 -1.9158 -1.1560 0.2449 0.4043 -0.1163 0.2891 0.3557 -0.1267 -0.5439 -3.9400 0.1958 0.0745 -3.9782 -1.9130 -1.7862 -2.2434 0.0431 -0.2579 -0.0002 -0.3686 0.9093 -0.0982 -1.6437 -0.5524 5.4826 -0.2097 0.0399 0.5414 0.3768 -0.0113 1.1068 -0.1614 0.1813 -0.0024 0.0735 -1.9358 -0.1625 0.1315 -0.0194 -0.4804 -1.0147 -0.2439 2.7875 -0.5643 -0.7146 0.0172 0.0314 ans(:,:,2) = 1.0e+03 * 0.5548 -0.0984 0.0008 -0.0960 -0.3031 0.0461 1.7885 -1.0376 1.5430 0.4454 -0.0645 0.0322 -0.0087 -3.2729 -1.2941 0.0726 -0.0320 -0.0279 -2.8930 -1.8691 -0.0328 -0.0930 -0.0049 -0.0896 0.1070 0.6868 -0.0521 0.1542 -0.0003 0.9544 0.0149 -0.3385 -0.0011 -0.0897 0.6183 0.7832 0.6327 0.0790 0.0116 -0.0014 0.0061 -0.3589 2.1918 -0.9368 1.5913 0.1382 1.2877 -2.0711 0.0255 -0.3829 1.9441 0.1139 0.4635 -0.1396 -0.2455 0.0316 0.1161 -0.0210 0.3309 -0.3527 0.9439 -0.0353 3.6949 0.3163 -0.0268 0.9597 0.0845 -2.7303 -0.0987 0.0626 -0.1570 -0.0033 -0.1265 0.7005 -0.3725 0.9995 -0.1999 -6.2480 0.4085 0.0569 -0.3797 -0.5586 0.0135 -0.3722 -2.4052 -0.1805 -0.0838 0.0126 0.9585 0.3733 0.2459 -0.0319 -2.9590 0.7130 -0.1390 2.0315 -0.2976 1.0833 -0.0411 -0.0081 ans(:,:,3) = 1.0e+03 * 0.2161 0.1166 -0.0003 -0.0097 1.1480 -0.0530 -1.5336 -1.9428 2.3949 0.9751 -0.0452 -0.0688 0.0104 1.3030 1.3895 -0.0600 -0.0723 0.0551 -2.3745 -0.6813 0.0313 -0.0592 0.0027 -0.0548 -0.8950 -0.1873 0.0382 0.7471 0.0043 -0.1827 0.0689 1.8361 0.0070 0.2285 0.0827 1.5524 -1.3153 0.1082 -0.0017 0.1867 -0.0261 -0.1592 1.4947 -0.2021 -0.3260 -0.2471 0.5076 -0.1657 0.0521 -0.2802 2.1277 0.0320 -0.2145 0.1151 0.2091 0.0401 0.4789 0.0500 1.2952 0.1227 0.6949 0.0049 2.8238 -1.2226 -0.0479 -0.9945 0.1488 -1.5113 -0.0681 -0.0128 0.5560 -0.0036 0.6234 1.8424 0.1723 -1.5271 1.2568 -2.0999 0.3055 0.4523 -0.3800 0.0053 0.0019 0.0172 4.1116 -0.2051 0.8835 0.0152 -1.7819 -0.7187 0.1370 0.0494 2.2053 -0.3857 -0.0237 0.8770 -0.1084 1.2176 -0.0369 -0.0027 ans(:,:,4) = 1.0e+03 * 0.0487 0.2317 0.0049 0.0115 -1.1350 0.0400 0.7003 -0.4554 -2.1820 3.1301 0.0693 -0.0423 0.0006 0.5858 0.3164 0.2800 -0.2348 -0.0199 0.9224 0.4876 0.0974 0.1408 -0.0083 0.1506 2.5522 0.2127 0.0396 -0.5696 -0.0245 -0.3373 0.0479 -1.7514 0.0275 -0.0389 -0.0150 -0.9539 -0.2160 0.4691 -0.0030 -0.1205 1.1532 0.2245 0.4839 0.1752 0.3257 -0.0874 -0.4269 -0.0343 -0.0458 -0.3761 -2.3401 0.0297 -0.1131 -0.0201 -0.1339 0.0260 0.8442 0.1297 0.0265 -0.0148 -0.3138 -0.0024 -1.4133 1.1363 0.1795 0.4713 0.0553 0.3793 0.0756 0.0905 -1.1334 -0.0060 0.2514 0.4947 0.5701 1.6728 -0.0146 -0.5682 -0.6456 -0.2824 1.7720 -0.0131 0.0002 -0.0249 -1.9177 -0.0763 -0.9529 0.0023 -0.5758 0.6177 0.1761 0.9685 -0.2402 -0.9871 0.0292 -0.9016 0.0023 1.1187 0.0560 0.0021 ans(:,:,5) = 1.0e+03 * 0.0123 -0.1263 -0.1184 0.0010 0.1592 0.0673 0.5917 0.0985 -1.3615 1.6224 -0.0020 0.0791 -0.0020 -1.0329 0.2132 0.1375 -1.9260 0.0856 -1.0169 -0.0521 0.0162 -0.3789 -0.0905 -0.5350 -2.9087 -0.3092 -0.6521 -1.5611 -0.0054 0.2477 -0.0066 0.7419 -1.1866 -0.1062 0.0111 -0.3493 -0.3378 0.7729 0.0057 -0.4347 0.5746 -0.1374 -0.0265 -0.2007 0.8046 -0.0469 -1.1731 0.0071 -0.1420 -0.5401 -3.1006 -0.0905 -0.0107 -0.0028 -0.3658 0.0912 -0.3484 0.1649 0.0256 0.0039 -0.2781 0.0098 -2.0469 2.1577 1.1344 -0.1228 -0.0216 0.6608 0.0981 -0.0820 -0.0831 1.2717 0.1548 0.1591 1.5239 -0.8890 0.0117 0.5500 -1.1777 -1.4951 -3.6245 0.0247 -0.0029 -0.0190 2.7961 -0.1441 -0.3082 0.0041 0.3312 -0.9943 0.5978 0.6597 0.2596 -1.7784 0.0107 0.3188 0.0010 -2.0457 -0.2007 -0.0023 ans(:,:,6) = 1.0e+03 * 0.0147 0.9695 -0.4085 0.0073 0.5125 -0.1835 0.3771 0.0651 0.8433 -2.5413 -0.0102 1.1079 -0.0758 -0.4779 -0.2420 -0.1111 -1.3065 0.0547 0.6376 -0.0910 0.0050 -0.7821 -0.0141 -0.1624 -3.4018 -0.0467 0.7439 2.4332 -0.1531 -0.0712 -0.1418 1.3759 -0.2542 0.0696 0.0338 -0.6785 0.3172 -0.2422 -0.0507 -0.0469 -1.2662 0.7488 -0.0094 0.4381 -0.0465 0.6162 0.4594 0.0106 -0.2854 1.1993 -3.3357 0.1044 -0.0068 -0.0353 1.0000 -0.0185 0.4730 1.0232 0.0486 0.0102 -0.7562 0.0660 -1.6987 2.0312 5.4035 0.3118 -0.4724 0.1126 1.5206 -0.2116 0.1424 -1.2436 0.4920 -0.1349 -0.1853 0.6794 -0.0241 0.0045 -0.1108 0.9925 0.2853 -0.0317 0.0019 -0.0555 0.9842 -0.0565 0.3614 0.0749 -0.0874 -0.0092 -0.7921 -0.2479 -0.3436 0.0167 -0.0526 0.1412 0.0005 -2.4978 -0.1111 0.0556 ans(:,:,7) = 1.0e+03 * -0.0587 -1.7406 -2.5186 0.0456 -0.7051 -1.2698 0.0406 0.0128 -0.9802 -0.6957 -0.0115 -1.0167 -0.0737 -1.0825 0.1703 0.0375 -2.1573 0.1084 -0.2790 0.2634 -0.0060 1.5555 0.0103 0.2859 3.0541 0.1793 -0.6313 0.4402 -0.1202 -0.1697 -0.1491 -0.4887 0.8646 0.1112 0.2601 -0.3592 -0.1279 0.0531 -0.0564 -0.0316 -0.7836 -0.5057 0.0142 0.3290 0.2216 0.5756 0.8656 -0.1019 0.4223 -2.9097 4.0067 0.2136 0.0160 0.0887 -0.1938 -0.0367 0.1357 0.0132 -0.0375 -0.1195 -1.2394 -0.8909 -0.0154 -0.4586 -2.2080 0.1415 -0.6050 -0.1305 1.2304 3.0558 -0.1635 1.3280 0.2075 0.0489 -0.0715 0.6791 -0.0164 0.0055 0.2243 -0.6390 0.1702 4.9850 0.0228 -0.5795 -0.4932 -0.1007 -0.4418 0.1526 -0.0777 0.0159 2.4286 -0.2602 -0.5372 0.0005 -0.4539 -0.0140 0.0005 -4.7019 0.1131 0.1743 ans(:,:,8) = 1.0e+03 * -0.2432 0.2910 0.4954 0.0452 -0.4932 3.4640 0.0764 -0.0446 1.9425 0.0323 0.0151 -2.6019 0.8880 0.1438 -0.6887 -0.0026 -1.8418 -0.4053 0.7174 -0.1355 -0.0090 1.8980 -0.0075 0.0920 3.7190 0.2181 0.8395 0.6281 0.3811 -0.1492 0.3118 -0.2492 0.6317 0.2569 1.0194 0.3341 -0.4045 0.0855 -0.0056 0.0397 -0.5002 0.2463 -0.0397 0.4238 0.2204 0.1772 -1.0994 -0.3634 -0.0630 4.5175 -1.9564 -1.4933 0.0066 0.3613 0.0037 -0.0573 -0.1363 0.0255 1.0366 -0.0919 -2.1663 -1.4409 0.0217 0.6621 0.9296 -0.2345 -1.9228 -0.2539 0.8148 -1.8186 0.0382 2.1570 -0.0354 0.2424 -0.0399 -0.4143 1.1373 -0.0198 -0.4196 -1.1056 0.0140 -5.3316 0.1869 0.3986 -0.4495 -0.1086 -0.3862 -0.2743 -0.2234 0.0275 4.6082 0.4561 -1.8216 -0.0005 -1.3266 -0.0080 0.1196 -4.8760 -0.2152 2.7687 ans(:,:,9) = 1.0e+03 * -0.9795 0.0985 -0.5035 -1.1154 1.0842 -1.5747 0.0667 0.0169 -1.5416 0.0561 -0.5206 -0.5209 2.0326 0.1196 0.5917 0.0134 -1.2410 0.6277 -0.3410 -0.4659 -0.1198 0.0083 0.0115 -0.0542 -0.5183 0.1783 0.3374 -0.3589 1.1071 0.1769 -0.7744 0.0293 0.3191 -0.0008 -1.3808 -0.2796 -0.4266 -0.0968 0.0002 -0.0627 0.0739 0.0511 -0.8685 -0.4040 0.0648 -0.4922 1.1537 -1.0522 -0.0940 -3.0552 2.3697 1.8907 0.1617 2.0301 -0.0024 -0.1235 -0.4088 -0.0446 -0.2868 0.4578 -0.0102 -0.8442 0.0100 -0.5996 -0.4223 -0.8341 -3.8213 0.2583 0.9877 -0.2152 -0.0245 -3.7601 -0.0355 -0.5708 -0.0093 0.0893 1.1142 0.0177 0.2627 1.1546 -0.0054 2.9371 0.1607 0.4371 0.0801 -0.0784 1.0046 -0.0797 -0.2499 -0.0219 -0.1711 -0.7635 -2.2812 -0.0000 -4.5161 -0.0193 -0.0946 -5.3174 0.1386 -0.6493 ans(:,:,10) = 1.0e+03 * -1.8285 -0.0459 0.3710 -1.0544 -0.0295 -0.2060 -0.1172 -0.0155 -2.7829 -0.0500 0.8705 0.5804 -1.9159 0.1201 1.2544 0.0248 -0.1495 -0.0492 -0.5480 0.3170 -0.5127 -0.0224 -0.1554 0.3940 0.5743 0.6379 -0.4223 -0.0497 -0.3521 -0.1269 0.1499 0.0325 1.2704 -0.0020 -0.3761 0.0168 -0.1987 0.7135 0.0022 -0.6002 -0.0517 -0.0635 -1.6864 0.2540 -0.0055 0.3004 -4.7046 -0.6652 0.0389 0.7754 -3.4604 -0.6530 -0.5238 -1.4832 -0.0070 5.4978 -1.6071 0.0487 0.2924 0.1958 -0...