Cody

# Problem 1940. Decimation - Optimized for speed

Solution 1928573

Submitted on 10 Sep 2019 by Nikolaos Nikolaou
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
assert(isequal(speed_decimation(10,3),4))

y = 4

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

y = 676

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

y = 543

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

y = 3

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

y = 8

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

y = 1

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

y = 1773

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

y = 1×0 empty double row vector y = 100000 y = 68929 y = 92620 y = 32942 y = 40333 y = 54212 y = 27152 y = 67341 y = 42610 y = 77328 y = 82991 y = 13252 y = 91717 y = 6850 y = 45758 y = 71249 y = 38339 y = 86953 y = 63331 y = 66903 y = 72606 y = 83990 y = 87828 y = 46101 y = 99979 y = 47141 y = 16871 y = 60389 y = 51549 y = 76409 y = 42868 y = 78390 y = 79590 y = 27573 y = 95835 y = 53636 y = 36954 y = 39891 y = 45943 y = 63811 y = 71589 y = 70886 y = 49313 y = 4069 y = 93694 y = 96031 y = 20739 y = 41403 y = 93714 y = 60023 Actual Time = 421 msec y = 38339 y = 162859 y = 151602 y = 99465 y = 462955 y = 559860 y = 337009 y = 546467 y = 563784 y = 364193 Actual Time = 702 msec y = 210856 Actual Time = 2076 msec