Cody

Solution 2104420

Submitted on 24 Jan 2020 at 9:12
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   Fail
A = [1 2 3 4 5 6]; C = [6 24 60 120]; assert(isequal(moveprod(A,3),C))

B = 2 6 24 60 120 30

Assertion failed.

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

Index exceeds the number of array elements (0). Error in moveprod (line 5) dim = s(1); Error in Test2 (line 3) B = moveprod(A,2);

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

B = -1 -4 12 18 -12 2 0 0 2 -6 3 -18 12 -6 15

Assertion failed.

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

B = -0.4053 -0.3870 2.3221 1.1611 1.2159 0 0 0 0.1935 0.6079 -1.8238 1.1611 1.1611 -0.9675 1.5198

Matrix dimensions must agree. Error in Test4 (line 8) assert(max(abs(B(:) - C(:))) <= max(abs(C(:)))*1e-12 && isequal(size(B),size(C)))

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

B(:,:,1) = 120 -320 -18 -162 -24 -336 140 63 0 -40 -80 -400 108 144 560 28 50 -12 -64 -36 -360 210 2 -18 -72 800 -8 -36 400 70 -432 540 0 0 -14 60 200 0 0 128 300 -18 -50 16 0 -180 168 -144 0 126 162 -12 120 0 -72 240 -500 0 8 0 160 0 32 90 0 -112 24 49 -150 -32 540 -168 -392 378 -112 -20 -48 -36 -9 -56 0 -630 224 0 -70 -280 128 36 -54 280 216 0 -42 -144 -48 315 12 0 -378 -210 B(:,:,2) = -1080 1280 -90 -486 -24 -336 1120 189 0 40 -720 1200 864 720 3360 280 250 -120 192 -360 -1440 -1470 -6 54 -720 -2400 -80 -108 0 -560 3024 0 0 0 -70 -120 -1400 0 0 -384 -2700 18 300 16 0 -1440 1680 -1008 0 126 1134 36 960 0 -72 1200 0 0 8 0 -800 0 256 -180 0 -1008 48 196 -1050 -256 4860 168 1960 -1890 336 100 96 252 36 224 0 1890 -2240 0 350 280 -896 -36 -324 -1400 864 0 378 1152 -480 0 36 0 2268 -630 B(:,:,3) = 3240 7680 810 2430 -240 1680 -2240 -1701 0 -200 3600 -2400 -5184 2160 6720 -1400 -2000 -360 -1152 -2520 12960 1470 30 -486 0 -12000 240 108 0 560 0 0 0 0 280 1080 11200 0 0 -384 -2700 -18 2700 80 0 14400 11760 2016 0 1008 9072 -216 -9600 0 648 -2400 0 0 -16 0 6400 0 512 540 0 1008 240 -588 -5250 -1024 -43740 840 -3920 -18900 2016 600 -480 -1260 216 -1792 0 3780 -6720 0 2100 1960 896 216 -2592 1400 -864 0 378 5760 -480 0 108 0 13608 4410 B(:,:,4) = 1620 4800 -1080 -1620 -840 1890 -896 15309 6720 360 -14400 0 5184 1200 840 -600 0 720 -5760 -15120 -14580 -294 240 -108 0 -2400 120 -108 0 -392 0 0 -3200 192 1400 -720 -39200 0 -48 192 1350 -24 -27000 480 -13824 -21600 -2940 -2016 0 2520 -30240 216 17280 0 -360 -3360 0 0 -16 0 0 0 -2304 -162 -324 864 240 2940 8750 -1536 -4374 240 -560 6300 1512 -5400 420 2100 -144 -2688 0 1134 -960 -600 -300 -3430 448 864 -18144 1400 -1152 0 -270 640 480 0 864 0 -7560 -5670 B(:,:,5) = 4320 0 -360 -1080 1890 -315 1344 5103 -1680 -1440 14400 0 -5184 600 -336 -1350 0 -1440 2880 11760 14580 -98 2400 -432 0 -1440 -150 -54 0 112 0 0 -3200 -1152 7000 -144 -23520 -1890 -96 216 1800 -16 -48600 -840 6144 -4320 -2520 -672 162 -1080 -5040 162 34560 0 -2160 1680 0 0 48 0 0 0 1440 -486 1620 -108 -90 -2940 8750 -2304 0 -400 720 5250 1512 0 -840 -9450 -288 4032 0 648 -480 -1200 150 -1715 112 -384 -16128 -2000 -2304 0 -630 -3200 -240 0 864 720 -8640 9450 B(:,:,6) = -5400 0 360 -600 -4410 -315 -1152 -5832 168 2160 25200 0 -4032 -1500 240 0 0 1440 2520 5880 14580 0 -2400 1296 0 -1440 -150 54 0 224 0 0 -8000 -960 -4000 -144 -11760 1260 -144 -1080 1080 -80 4860 -1680 -6144 -2880 -1680 336 243 480 2800 216 38880 -480 -270 -1470 0 0 144 0 0 0 -5760 486 -1080 270 -60 420 -875 1728 0 500 180 4500 -648 0 2240 3150 2592 1152 8640 -432 360 960 150 -1960 336 -672 5376 400 2048 -4200 3150 2400 1200 0 864 0 0 -7560 B(:,:,7) = 5400 0 72 -1600 0 3150 -1296 7776 216 -15120 -25200 0 1512 -1500 200 0 0 1440 5040 588 10935 0 -7200 -2160 0 3840 30 -144 -288 252 0 -252 16000 1920 -3200 -504 -8400 1620 72 -2160 -720 -560 -1620 15120 -3840 -2880 840 336 81 -4800 -1200 -432 -9720 480 -1350 294 3360 0 -288 0 0 0 -1440 972 -360 300 -30 -1050 -375 864 0 -1500 -180 -900 -648 0 -1120 4050 4536 -864 960 144 -72 -1440 0 -9800 480 -4032 2688 160 0 2520 -1050 -1500 720 0 -2304 0 0 0 B(:,:,8) = -7200 0 64 0 0 4410 3888 2592 -216 30240 0 0 2520 1000 1000 0 0 -3360 8400 -588 9720 0 -5760 -720 -1960 -6912 20 864 648 -2268 4320 2520 -12800 -960 -4000 560 -3150 0 -72 -19440 -6480 4480 -720 27216 2400 576 960 -168 81 -6000 1350 576 9720 -800 -1500 -294 2240 -480 1008 0 0 8000 -720 1620 -2520 2700 42 700 -675 -2160 0 2700 270 450 108 0 1568 2430 -6804 -216 -1200 -72 -144 0 0 -11200 1440 -6048 -336 -1600 0 1890 5250 900 6480 0 -6912 0 0 0 B(:,:,9) = -7200 0 64 0 0 -980 -9720 288 -135 -13440 0 0 -3780 -1200 -6000 0 -2916 -8400 0 -686 1080 0 -1440 -1080 -4900 -17280 0 -96 -288 -3240 -3240 -5880 -1600 1440 -5600 -280 -2250 0 -648 38880 -12960 -7840 -216 36288 -2000 -192 -5760 -105 -135 -6000 -540 -4032 -9720 -2400 -2100 -252 -4480 720 0 0 7200 -9000 640 4860 -5880 -18...

Unable to perform assignment because the size of the left side is 1-by-1-by-96 and the size of the right side is 100-by-1. Error in Test5 (line 8) C(m,n,:) = moveprod(squeeze(A(m,n,:)),k);

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

B(:,:,1) = 5.1601 -7.8530 86.6664 -12.8381 -59.4220 -36.4544 -1.5589 -25.9066 -11.6411 36.1275 4.4609 -47.2046 52.9974 19.8783 -2.8149 44.1404 31.8445 15.4232 -54.2898 8.2168 -15.2392 3.3045 14.1584 14.9251 -14.3828 6.1457 -7.0944 31.7643 -37.9976 -2.9501 -34.7285 30.0232 -25.4570 39.6606 -4.6585 50.2212 -65.4074 18.3404 47.8504 -47.7883 75.7485 49.4105 -34.8974 17.5492 4.6231 1.2184 -22.0218 -42.9979 -26.7421 -10.8889 -13.0198 -62.4617 8.5421 13.5893 -21.7261 14.7349 15.0209 7.2048 12.7442 48.0252 -4.4822 -4.1034 -0.5039 -82.6827 55.7457 -7.8595 -28.5989 -1.3438 -27.2246 -5.7285 -36.9260 11.3972 -26.6766 -5.7730 -65.3322 -28.5463 18.0038 -47.4891 32.3574 1.5988 -26.6170 -7.0565 54.0915 3.9201 -12.0645 41.4029 -26.6497 -6.2164 15.9171 26.8041 -9.6882 30.6413 -32.1820 36.2448 29.8225 -7.5540 26.2612 8.0708 -19.5857 -27.1423 B(:,:,2) = -28.1181 -67.7678 323.3791 -13.8308 -488.7193 -139.1739 -5.2899 -96.4818 -47.3734 -166.0396 -30.1210 -292.3886 111.4894 128.4530 10.5185 40.4247 -236.7246 99.5135 302.4257 53.6380 19.3875 7.3635 -7.1296 -55.0673 99.1931 20.5495 -21.4891 -159.8623 -248.4196 20.8410 -146.9295 49.9826 -140.9660 161.1253 -22.7638 501.1012 -225.0213 171.4823 -467.2354 258.0093 226.3149 -328.2744 -225.1819 -34.8508 5.1615 -1.8716 107.9387 149.5367 -209.1190 -3.1482 -125.7439 -139.1948 35.1158 -69.9398 76.5899 108.7509 115.7916 -49.4008 -99.3076 321.5293 -7.0486 -6.9350 -2.6254 108.8117 -120.4643 -47.8482 -86.2687 -11.8549 100.7886 -29.1268 -172.1160 49.7564 227.0827 55.6493 -505.5743 8.2244 27.7334 397.4664 278.4102 -5.2715 -210.7919 8.5687 254.1492 -21.4672 44.1896 66.4374 227.0634 55.1403 -143.8372 230.5974 2.0045 -191.0298 -10.8366 -183.2116 44.1294 -47.8215 203.4965 -72.7594 184.5537 9.6867 B(:,:,3) = 1.0e+03 * 0.0745 -0.6460 -1.4882 0.1186 -0.6472 -0.0144 0.0189 0.2563 0.0511 -0.4806 0.0318 2.3771 -0.2512 0.4653 -0.0564 0.0107 -2.2304 0.6352 0.8634 -0.0788 -0.0047 0.0249 0.0003 0.4831 0.2641 -0.1810 0.2090 -0.8081 -1.2005 -0.0789 0.8817 0.0459 -0.1602 -0.3624 -0.1903 -2.9227 -0.7093 -0.2996 4.4160 1.4740 2.1183 1.3834 1.0621 -0.2789 -0.0467 -0.0135 0.2189 -0.9908 -1.3473 -0.0136 -1.2149 -0.6104 -0.3391 0.2180 -0.1675 -0.5972 0.6801 -0.2990 0.0305 -2.8613 0.0454 -0.0128 0.0113 0.8351 -0.0808 0.0613 0.7970 0.0590 -0.6140 -0.0907 -0.2530 0.4368 -1.2445 0.0315 2.5584 -0.0109 -0.0663 -3.4537 -1.6823 0.0368 1.0527 -0.0241 1.5835 -0.1785 0.4142 0.4565 0.3192 0.4234 0.8809 -1.2332 0.0050 -0.1932 0.0624 0.6591 0.0255 -0.3813 1.3622 -0.5914 -1.4541 0.0738 B(:,:,4) = 1.0e+03 * 0.2106 1.5679 0.6151 0.0242 -0.3734 -0.0304 -0.0061 -0.3783 -0.0288 0.7452 -0.0557 1.3301 -0.2277 0.4777 0.7907 0.0117 -1.7068 0.9848 1.4846 0.0927 -0.0157 0.0953 0.0002 0.1646 -0.7170 0.0943 -0.0505 0.8237 1.0643 0.0800 0.8373 0.0782 0.2711 0.2203 -0.0789 -0.1347 -0.1322 0.1462 -2.9488 1.1009 -0.1992 0.0578 1.2365 -0.4244 0.0024 0.1845 -0.0174 0.9356 -1.4154 0.0058 -0.2380 -0.3487 -3.1204 0.2828 -0.0818 0.9937 -0.2256 -0.2934 -0.0626 1.2118 -0.2182 -0.0163 -0.0752 -0.0982 -0.0340 0.0520 0.1167 0.1042 -1.1085 -0.0231 -0.1451 -1.3605 -0.1982 0.1081 0.3766 -0.0076 0.0517 -1.7658 -1.3658 -0.1676 0.2937 0.0468 -0.8162 -0.5084 -0.6682 0.2373 -0.0840 -3.9109 2.0185 0.4158 -0.0344 -0.0584 0.0909 0.7082 0.0473 0.5484 -0.2207 2.3416 1.8209 -0.0212 B(:,:,5) = 1.0e+03 * -0.0294 -1.9611 0.0843 0.1463 0.1985 -0.0136 -0.1370 -0.0184 -0.0407 -0.1147 0.0374 0.9465 0.2436 0.0639 -0.6697 -0.0014 0.4539 -0.9808 -0.1187 0.3926 0.0115 -0.0672 -0.0008 -0.7823 1.0564 -0.2428 -0.0470 -0.1445 -0.6200 1.0363 1.1496 -0.0625 -0.0971 -0.0910 0.5588 0.0314 0.0277 -0.0266 -1.7564 0.7301 -0.0998 0.0476 -0.7968 0.0725 -0.0205 -0.8700 -0.0082 -0.2168 0.7730 0.0390 0.1214 0.3935 2.7226 0.6074 0.2822 -3.1118 1.1850 0.2593 -0.2182 0.6938 -0.2924 0.1807 0.2758 -0.0845 -0.0051 0.1183 0.1879 -2.1633 0.7176 -0.1429 0.2323 -1.0213 -0.2540 0.0011 0.3164 -0.0130 -0.0105 1.3586 -2.3120 0.4931 -0.0797 -0.0783 0.3348 0.9094 2.7879 0.0599 0.0658 3.5098 -2.3984 -0.1552 0.0152 0.1282 -0.0850 -0.5328 -0.0684 -0.3584 0.2917 -1.6646 -2.6350 0.0473 B(:,:,6) = 1.0e+03 * -0.0086 0.2589 -0.2127 0.1672 -0.1543 -0.0346 0.1298 0.0472 -0.0286 -0.1201 0.0531 0.8502 0.6276 0.0704 0.4450 -0.0085 -0.1772 -0.5670 0.1857 -0.2108 -0.0063 -0.1478 -0.0001 0.0760 0.4241 -0.4361 0.1140 0.2771 -0.0253 -0.7934 -2.0491 0.1990 -0.0516 0.1641 -0.0288 -0.0312 -0.0162 0.0100 -0.8836 -0.0520 -0.0543 0.0283 0.8579 -0.3347 -0.0961 -4.5164 0.0158 -0.0533 0.5583 -0.9582 0.0180 -1.3427 -2.4379 -1.1381 0.7267 -3.8765 -0.6907 0.3167 -0.1048 0.3508 -0.4698 -0.6145 0.5223 0.0994 0.0074 0.0333 -0.1776 -1.4039 1.2574 0.0397 0.1021 -1.7748 -0.1051 0.0004 -0.2300 -0.3845 -0.0336 -1.3016 -1.9301 -1.3099 -0.0251 -0.6347 0.2672 -0.1176 -5.4549 -0.3694 -0.0094 2.9554 -1.0561 0.0288 0.3212 -0.1798 1.7210 0.1921 0.0512 -0.2169 0.0012 -1.7120 -2.2365 0.6300 B(:,:,7) = 1.0e+03 * -0.0293 -0.1503 -0.3744 -0.0116 -0.0489 0.1455 0.0514 -0.1361 0.2368 0.3259 0.1261 0.5223 2.6204 0.0632 0.1256 0.2160 -0.1317 -0.6635 0.2309 0.3692 -0.0903 -0.0473 -0.0010 -0.0352 1.0786 0.4205 -0.0319 0.5275 0.0406 1.3101 0.1186 -0.4761 -0.0848 0.5713 0.0260 -0.0440 0.0163 0.0142 -0.4969 0.0635 0.0341 0.0250 0.0630 -0.2742 -0.0685 -0.1243 -0.0003 -0.0171 -0.0384 -0.7777 -0.0158 1.0528 0.3926 -2.7690 2.9324 1.0210 1.0738 0.3734 3.4143 -0.2091 0.1883 -3.0121 1.0897 -0.0040 0.0418 0.2264 0.1525 -1.7944 -1.1104 0.0924 -0.2288 0.3991 0.0809 -0.0038 0.1566 -1.4586 -0.0723 -0.8094 3.1906 1.8167 0.0231 -1.6825 -0.3846 0.0011 -3.3020 0.2809 0.0493 -3.2484 0.7670 0.0063 0.2607 -0.7582 1.2967 0.2641 0.5053 -0.0173 0.0006 1.6269 -1.9990 -0.0313 B(:,:,8) = 1.0e+03 * -0.0518 0.1612 -0.2349 0.0199 -0.0778 -0.1444 0.0795 0.0541 -0.0839 -0.1329 -0.1822 0.7371 0.8396 0.1257 0.1143 -0.1057 -0.3679 0.0988 0.1371 -0.6316 0.1504 -0.0562 0.0003 -0.0884 -0.7121 -1.0044 0.0504 0.6712 -0.0063 -1.6492 0.1917 -0.6861 0.1253 -1.0531 0.0502 0.4614 -0.0782 -0.0972 0.5201 -0.0798 0.1378 0.6618 0.0293 0.0214 -0.2016 -0.1054 -0.0044 -0.0019 0.0011 -2.1001 0.3582 1.3594 -0.1355 2.8700 -2.9993 1.0420 2.1542 0.6602 -2.9565 -0.1419 0.0423 3.3298 -1.2544 0.0180 0.0329 -0.4666 0.7679 1.9487 1.0059 -0.4030 -0.0847 -0.2590 -0.9923 0.0042 -0.6764 -1.0137 -0.0601 0.3633 4.6732 -1.1411 0.0249 -1.7823 0.0124 0.0002 -1.9789 -0.4480 -0.2600 3.0192 0.6853 0.0345 -0.0365 1.6259 -0.5013 -0.0905 -0.3529 -0.0017 0.0027 1.7897 2.6818 -0.0210 B(:,:,9) = 1.0e+03 * 1.0530 -0.0622 -0.1097 0.0148 -0.1369 -0.1840 -0.1104 -2.3400 -0.0491 -0.6194 -0.1398 -0.4161 -0.6530 1.0981 -0.1296 0.1746 -0.8555 0.0854 -0.6578 -0.2844 -0.1120 -0.3871 0.0002 -0.0359 0.2937 -2.5202 -0.0528 7.2940 -0.0140 1.9248 0.1476 -0.2023 0.2111 3.3856 -0.0246 -0.4105 -0.1648 -0.6768 0.7033 0.1373 0.1518 -0.2861 -0.0134 0.0483 -0.1360 -0.1125 0.0097 -0.0081 0.0010 1.5960 -0.1406 -1.0949 -0.0306 -2.8559 3.7304 -0.6050 0.3251 -0.5062 -1.2997 -0.0050 0.0180 4.4430 1.6547 -0.0072 -0.0100 -0.4625 -1.0199 1.4099 -0.9218 -0.3938 0.0741 -0.0254 0.7346 1.3989 0.1622 0.7175 1.4543 0.3609 -4.3645 -1.6694 0.0351 -3.5750 -0.0319 0.0004 1.9066 2.3750 -0.0798 0.6604 -0.9151 -0.0715 -0.0526 -0.5071 0.1027 -0.1996 0.1425 -0.0210 0.0013 4.1317 -2.3299 -0.0015 B(:,:,10) = 1.0e+03 * -0.2749 0.5201 0.1125 -0.0539 -0.1923 0.1490 0.3052 0.7765 -0.0939 0.5609 -0.0041 -0.2741 -0.1741 1.2990 0.3366 -0.3012 1.1964 0.1997 -0.0698 -0.7527 -0.1402 -0.0383 -0.0285 -0.1063 -0.8436 -1.9045 -0.0684 4.9252 -0.3675 1.2666 0.1028 0.1632 0.6708 3.5458 0.8588 -0.2965 -0.1364 1.6482 -0.2881 -0.1856 0.0607 -0.3464 -0.0164 -0.0338 -0.2134 -0.1218 0.0098 -0.0775 -0.0010 -0.8641 -0.6029 -1.1595 -0.0681 0.0641 3.1945 -0.1083 0.5338 -0.3501 2.0144 0.0018 -0.0359 -3.1683 -0.7327 -0.0003 0.0174 ...

Unable to perform assignment because the size of the left side is 1-by-1-by-97 and the size of the right side is 100-by-1. Error in Test6 (line 8) C(m,n,:) = moveprod(squeeze(A(m,n,:)),k);