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

Solution 144120

Submitted on 3 Oct 2012 by Richard Zapor

Correct

272Size
`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

```tic
L=1024;
while 1 % Loop until create a Gtruth with no repeated 16 segments
Gtruth=randi(4,1,L,'uint8')-1;
Gseg=zeros(L-15,16,'uint8');
for j=1:L-15
Gseg(j,:)=Gtruth(j:j+15);
end
Gsegv=uint32(Gseg(:,1));
for j=2:16
Gsegv=4*Gsegv+uint32(Gseg(:,j));
end
if size(unique(Gsegv),1)==L-15
break
end
end % while create valid Gtruth
segs=Gtruth(1:48); % First segment is a required
segs=[segs;Gtruth(L-47:end)]; % Last Segment is required
ptr=0;
while 1
ptr=ptr+randi(32);
if ptr+48>L,break;end
segs=[segs;Gtruth(ptr:ptr+47)];
end
v=randperm(size(segs,1)); % Segs Scrambled Over Easy
segs(:,:)=segs(v,:);
Gout = Genome_003(segs);
toc
%assert(isequal(Gout,Gtruth)||isequal(Gout,fliplr(Gtruth)))
assert( isequal(Gout,Gtruth) )
```
```Elapsed time is 0.132577 seconds.
Elapsed time is 0.154826 seconds.
```
2
Pass

```%%
tic
L=2000+randi(200);
while 1 % Loop until create a Gtruth with no repeated 16 segments
Gtruth=randi(4,1,L,'uint8')-1;
Gseg=zeros(L-15,16,'uint8');
for j=1:L-15
Gseg(j,:)=Gtruth(j:j+15);
end
Gsegv=uint32(Gseg(:,1));
for j=2:16
Gsegv=4*Gsegv+uint32(Gseg(:,j));
end
if size(unique(Gsegv),1)==L-15
break
end
end % while create valid Gtruth
segs=Gtruth(1:48); % First segment is a required
segs=[segs;Gtruth(L-47:end)]; % Last Segment is required
ptr=0;
while 1
ptr=ptr+randi(32);
if ptr+48>L,break;end
segs=[segs;Gtruth(ptr:ptr+47)];
end
v=randperm(size(segs,1)); % Segs Scrambled Over Easy
segs(:,:)=segs(v,:);
Gout = Genome_003(segs);
toc
%assert(isequal(Gout,Gtruth)||isequal(Gout,fliplr(Gtruth)))
assert( isequal(Gout,Gtruth) )
```
```Elapsed time is 0.031634 seconds.
Elapsed time is 0.031719 seconds.
```
3
Pass

```%%
tic
L=4000+randi(200);
while 1 % Loop until create a Gtruth with no repeated 16 segments
Gtruth=randi(4,1,L,'uint8')-1;
Gseg=zeros(L-15,16,'uint8');
for j=1:L-15
Gseg(j,:)=Gtruth(j:j+15);
end
Gsegv=uint32(Gseg(:,1));
for j=2:16
Gsegv=4*Gsegv+uint32(Gseg(:,j));
end
if size(unique(Gsegv),1)==L-15
break
end
end % while create valid Gtruth
segs=Gtruth(1:48); % First segment is a required
segs=[segs;Gtruth(L-47:end)]; % Last Segment is required
ptr=0;
while 1
ptr=ptr+randi(32);
if ptr+48>L,break;end
segs=[segs;Gtruth(ptr:ptr+47)];
end
v=randperm(size(segs,1)); % Segs Scrambled Over Easy
segs(:,:)=segs(v,:);
Gout = Genome_003(segs);
toc
%assert(isequal(Gout,Gtruth)||isequal(Gout,fliplr(Gtruth)))
assert( isequal(Gout,Gtruth) )
```
```Elapsed time is 0.067712 seconds.
Elapsed time is 0.067811 seconds.
```