Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 171092

Submitted on 30 Nov 2012 by @bmtran

Correct

2000Size
Leading solution size is 0.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
feval(@assignin,'caller','score',2000);

                    
2
Pass
 
%%
global num_ones b1 b2 b3 b4 b5 net_time
net_time=2000; % 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

                    
3
Pass
 
%%
global num_ones b1 b2 b3 b4 b5 net_time
w=uint32(randi(2^32,[65536*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 65536 values %.0f usec\n',dt);
assert(isequal(wexpect,vw),sprintf('Time to execute 65536 values %.0f usec\n',dt))
Time to execute 65536 values 15145 usec
4
Pass
 
%%
global num_ones b1 b2 b3 b4 b5 net_time
w=uint32(randi(2^32,[65536*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('Time to execute 4096*4096 values %.0f msec\n',net_time))
Time to execute 4096*4096 values 6227 msec
5
Pass
 
%%
global net_time
% net_time in ms
% Create graph data
net_time=min(2000,net_time); % Limit graph y-axis
feval(@assignin,'caller','score',floor(net_time));
%fh=fopen('Ham.m','wt');
%fprintf(fh,'%s\n',repmat('1;',[1,round(net_time/2)]));
%fclose(fh);