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 137497

Submitted on 10 Sep 2012 by Khaled Hamed

Correct

265Size
Leading solution size is 35.
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',0);

                    
2
Pass
 
%%
% Functionality Section
Pass=1;
w=6;
DNA=randi(4,1,1800000,'uint8')-1;
Patterns=randi(4,12,6,'uint8')-1; % Create more than needed
Patterns=unique(Patterns,'rows','stable'); % Elim dupes but maintain random
Patterns=Patterns(1:6,:); % Take first 6 random vectors
Patterns=unique(Patterns,'rows'); % Place in order for easier debugging
DNA_ID=1;
Locations = find_DNA(DNA, DNA_ID, Patterns);
if isempty(Locations),Pass=0;end
if max(size(Locations))<1024,Pass=0;end
for i=1:size(Locations,1)
      Pass=Pass && ismember(DNA(Locations(i,end):Locations(i,end)+w-1),Patterns,'rows');
    end
DNA=randi(4,1,1800000,'uint8')-1;
Patterns=randi(4,24,6,'uint8')-1; % Create more than needed
Patterns=unique(Patterns,'rows','stable'); % Elim dupes but maintain random
Patterns=Patterns(1:12,:); % Take first 6 random vectors
Patterns=unique(Patterns,'rows'); % Place in order for easier debugging
DNA_ID=2;
Locations = find_DNA(DNA, DNA_ID, Patterns);
if isempty(Locations),Pass=0;end
if max(size(Locations))<1024,Pass=0;end
for i=1:size(Locations,1)
      Pass=Pass && ismember(DNA(Locations(i,end):Locations(i,end)+w-1),Patterns,'rows');
    end
assert(isequal(Pass,1))

                    
3
Pass
 
%%
% Timing Section
DNA=randi(4,1,1800000,'uint8')-1;
Patterns=randi(4,12,6,'uint8')-1; % Create more than needed
Patterns=unique(Patterns,'rows','stable'); % Elim dupes but maintain random
Patterns=Patterns(1:6,:); % Take first 6 random vectors
Patterns=unique(Patterns,'rows'); % Place in order for easier debugging
DNA_ID=1;
Locations = find_DNA(DNA, DNA_ID, Patterns);
Locations = find_DNA(DNA, DNA_ID, Patterns);
t0=clock;
for i=1:10
 Locations = find_DNA(DNA, DNA_ID, Patterns);
end
dt1=etime(clock,t0)*1000; % msec conversion
fprintf('Your Set 1 Time = %i msec\n',floor(dt1))
Patterns=randi(4,24,6,'uint8')-1; % Create more than needed
Patterns=unique(Patterns,'rows','stable'); % Elim dupes but maintain random
Patterns=Patterns(1:12,:); % Take first 12 random vectors
Patterns=unique(Patterns,'rows'); % Place in order for easier debugging
t0=clock;
for i=1:10
 Locations = find_DNA(DNA, DNA_ID, Patterns);
end
dt2=etime(clock,t0)*1000; % msec conversion
fprintf('Your Set 2 Time = %i msec\n',floor(dt2))
% New DNA Set
DNA=randi(4,1,1800000,'uint8')-1;
Patterns=randi(4,12,6,'uint8')-1; % Create more than needed
Patterns=unique(Patterns,'rows','stable'); % Elim dupes but maintain random
Patterns=Patterns(1:6,:); % Take first 6 random vectors
Patterns=unique(Patterns,'rows'); % Place in order for easier debugging
DNA_ID=2;
Locations = find_DNA(DNA, DNA_ID, Patterns);
Locations = find_DNA(DNA, DNA_ID, Patterns);
t0=clock;
for i=1:10
 Locations = find_DNA(DNA, DNA_ID, Patterns);
end
dt3=etime(clock,t0)*1000; % msec conversion
fprintf('Your Set 3 Time = %i msec\n',floor(dt3))
feval(@assignin,'caller','score',min(400,floor(double(dt1+dt2+dt3)/30)));
Your Set 1 Time = 1988 msec
Your Set 2 Time = 3989 msec
Your Set 3 Time = 1989 msec