Cody

# Problem 810. Hamming Weight - Size Scoring

Solution 1981014

Submitted on 17 Oct 2019 by William
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
global num_ones b1 b2 b3 b4 b5 net_time net_time=4000; % default in case of time out (not needed) b1=uint32(1431655765); b2=uint32(858993459); b3=uint32(252645135); b4=uint32(16711935); b5=uint32(65535); num_ones=uint32(zeros(65536,1)); for i=0:65535 num_ones(i+1)=length( find( bitget( i, 1:32 ) ) ) ; end % Cody 0.996 sec

2   Pass
global num_ones b1 b2 b3 b4 b5 net_time w=uint32(randi(2^32,[4096*1,1])-1); for i=1:4 % Clear timing vw=Ham(w); end wexpect=num_ones(mod(w,65536)+1)+num_ones(floor(double(w)/65536)+1); %1.56 t0=clock; vw=Ham(w); vw=Ham(w); vw=Ham(w); vw=Ham(w); dt=etime(clock,t0)*250*1000; % avg of 4 runs in us fprintf('Time to execute 4096 values %.0f usec\n',dt); assert(isequal(wexpect,vw),sprintf('\nTime to execute 4096 values %.0f usec\n',dt))

Time to execute 4096 values 632 usec

3   Pass
global num_ones b1 b2 b3 b4 b5 net_time w=uint32(randi(2^32,[4096*1,1])-1); vw=Ham(w); % Three cycles of smaller vector vw=Ham(w); vw=Ham(w); w=uint32(randi(2^32,[4096*4096,1])-1); wexpect=num_ones(mod(w,65536)+1)+num_ones(floor(double(w)/65536)+1); %1.56 vw=Ham(w); % Big Prep file vw=Ham(w); % Big Prep file t0=clock; vw=Ham(w); vw=Ham(w); vw=Ham(w); vw=Ham(w); net_time=etime(clock,t0)*250; % avg of 4 runs fprintf('Time to execute 4096*4096 values %.0f msec\n',net_time); assert(isequal(wexpect,vw),sprintf('\nTime to execute 4096*4096 values %.0f msec\n',net_time))

Time to execute 4096*4096 values 295 msec