Cody

# Problem 1940. Decimation - Optimized for speed

Solution 1163868

Submitted on 15 Apr 2017
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
assert(isequal(speed_decimation(10,3),4))

Output argument "ans" (and maybe others) not assigned during call to "speed_decimation". Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in TestPoint1 (line 1) assert(isequal(speed_decimation(10,3),4))

2   Fail
assert(isequal(speed_decimation(1024,3),676))

Output argument "ans" (and maybe others) not assigned during call to "speed_decimation". Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1;

3   Fail
assert(isequal(speed_decimation(2012,50),543))

Output argument "ans" (and maybe others) not assigned during call to "speed_decimation". Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1;

4   Fail
assert(isequal(speed_decimation(30,5),3))

Output argument "ans" (and maybe others) not assigned during call to "speed_decimation". Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in TestPoint4 (line 1) assert(isequal(speed_decimation(30,5),3))

5   Fail
assert(isequal(speed_decimation(10,10),8))

Output argument "ans" (and maybe others) not assigned during call to "speed_decimation". Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1; Error in TestPoint5 (line 1) assert(isequal(speed_decimation(10,10),8))

6   Fail
assert(isequal(speed_decimation(2048,2),1))

Output argument "ans" (and maybe others) not assigned during call to "speed_decimation". Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1;

7   Fail
assert(isequal(speed_decimation(2048,1024),1773))

Output argument "ans" (and maybe others) not assigned during call to "speed_decimation". Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1;

8   Fail
t_in=clock; j=1:50; v=arrayfun(@(x) speed_decimation(100000,x),j); correct=[100000 68929 92620 32942 40333 54212 27152 67341 42610 77328 82991 13252 91717 6850 45758 71249 38339 86953 63331 66903 72606 83990 87828 46101 99979 47141 16871 60389 51549 76409 42868 78390 79590 27573 95835 53636 36954 39891 45943 63811 71589 70886 49313 4069 93694 96031 20739 41403 93714 60023]; assert(all(isequal(v,correct))); t_out=etime(clock,t_in)*1000; fprintf('Actual Time = %.0f msec\n',t_out) v=[100000:100000:1000000]; v=arrayfun(@(x) speed_decimation(x,17),v); correct=[38339 162859 151602 99465 462955 559860 337009 546467 563784 364193]; assert(all(isequal(v,correct))); t_out=etime(clock,t_in)*1000; fprintf('Actual Time = %.0f msec\n',t_out) assert(isequal(speed_decimation(2^20,2^9),210856)); t_out=etime(clock,t_in)*1000; t2=min(100000,t_out); fprintf('Actual Time = %.0f msec\n',t_out) feval(@assignin,'caller','score',floor(t2));

Out of memory. The likely cause is an infinite recursion within the program. Error in speed_decimation (line 3) s = mod(speed_decimation(s-1,ke)-1+ke,s)+1;