Cody

Solution 2104419

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

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

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

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

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

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