Cody

Solution 873680

Submitted on 14 Apr 2016 by Jan Orwat
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

Test Status Code Input and Output
1   Pass
A = [1 2 3 4 5 6]; C = [6 24 60 120]; assert(isequal(movprod(A,3),C))

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

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(movprod(A,2),C))

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 = movprod(A,3,2); assert(max(abs(B(:) - C(:))) <= max(abs(C(:)))*1e-12 && isequal(size(B),size(C)))

5   Pass
A = randi([-10,10],10,10,100); k = 5; dim = 3; B = movprod(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,:) = movprod(squeeze(A(m,n,:)),k); end end assert(isequal(B,C))

6   Pass
A = 20*rand(10,10,100)-10; k = 4; dim = 3; B = movprod(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,:) = movprod(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)))