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

Solution 269049

Submitted on 28 Jun 2013 by Richard Zapor

Correct

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

```%%
Pts=[5 5; 7 9];
dxy=[0 1];
Mxy=unique(Knights(Pts,dxy),'rows');
Mxy_exp =[4 5;5 4;5 6;6 5;6 9;7 8;7 10;8 9];
assert(isequal(Mxy,Mxy_exp))
```

2
Pass

```%%
Pts=[5 5];
dxy=[0 1;1 2];
Mxy=unique(Knights(Pts,dxy),'rows');
Mxy_exp =[3 4;3 6;4 3;4 5;4 7;5 4;5 6;6 3;6 5;6 7;7 4;7 6];
assert(isequal(Mxy,Mxy_exp))
```

3
Pass

```%%
pts=randi(20,6,2);
dxy=randi(6,4,2);
Mxy=unique(Knights(pts,dxy),'rows');
nP=size(pts,1);
ndxy=size(dxy,1);
mxy=[];
for i=1:nP
mxy=[mxy;
dxy(:,1)+pts(i,1) dxy(:,2)+pts(i,2);
-dxy(:,1)+pts(i,1) dxy(:,2)+pts(i,2);
dxy(:,1)+pts(i,1) -dxy(:,2)+pts(i,2);
-dxy(:,1)+pts(i,1) -dxy(:,2)+pts(i,2);
dxy(:,2)+pts(i,1) dxy(:,1)+pts(i,2);
-dxy(:,2)+pts(i,1) dxy(:,1)+pts(i,2);
dxy(:,2)+pts(i,1) -dxy(:,1)+pts(i,2);
-dxy(:,2)+pts(i,1) -dxy(:,1)+pts(i,2)];
end
Mxy_exp=unique(mxy,'rows');
assert(isequal(Mxy,Mxy_exp))
```