Cody

# Problem 44324. Rewrite setdiff to account for non-unique values

Solution 1277664

Submitted on 28 Sep 2017 by Noriko Hounoki
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
a=[1 1 2 3 4 5 6 7 8]; b=[1 3 4 5 6 7]; y_correct=[1 2 8]; assert(isequal(new_setdiff(a,b),y_correct)) assert(isequal(new_setdiff(fliplr(a),b),y_correct)) assert(isequal(new_setdiff(a,fliplr(b)),y_correct))

ap = 8 a = 1 1 2 3 4 5 6 8 b = 1 3 4 5 6 ap = 7 a = 1 1 2 3 4 5 8 b = 1 3 4 5 ap = 6 a = 1 1 2 3 4 8 b = 1 3 4 ap = 5 a = 1 1 2 3 8 b = 1 3 ap = 4 a = 1 1 2 8 b = 1 ap = 1 a = 1 2 8 b = 1×0 empty double row vector ap = 2 a = 8 6 5 4 3 2 1 1 b = 1 3 4 5 6 ap = 2 a = 8 5 4 3 2 1 1 b = 1 3 4 5 ap = 2 a = 8 4 3 2 1 1 b = 1 3 4 ap = 2 a = 8 3 2 1 1 b = 1 3 ap = 2 a = 8 2 1 1 b = 1 ap = 3 a = 8 2 1 b = 1×0 empty double row vector ap = 1 a = 1 2 3 4 5 6 7 8 b = 7 6 5 4 3 ap = 3 a = 1 2 4 5 6 7 8 b = 7 6 5 4 ap = 3 a = 1 2 5 6 7 8 b = 7 6 5 ap = 3 a = 1 2 6 7 8 b = 7 6 ap = 3 a = 1 2 7 8 b = 7 ap = 3 a = 1 2 8 b = 1×0 empty double row vector

2   Pass
a=repmat([1:10],1,2); b=repmat([1:5],1,2); y_correct=[6 6 7 7 8 8 9 9 10 10]; assert(isequal(new_setdiff(a,b),y_correct))

ap = 5 a = 1 2 3 4 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 b = 1 2 3 4 5 1 2 3 4 ap = 4 a = 1 2 3 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 b = 1 2 3 4 5 1 2 3 ap = 3 a = 1 2 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 b = 1 2 3 4 5 1 2 ap = 2 a = 1 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 b = 1 2 3 4 5 1 ap = 1 a = 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 b = 1 2 3 4 5 ap = 10 a = 6 7 8 9 10 1 2 3 4 6 7 8 9 10 b = 1 2 3 4 ap = 9 a = 6 7 8 9 10 1 2 3 6 7 8 9 10 b = 1 2 3 ap = 8 a = 6 7 8 9 10 1 2 6 7 8 9 10 b = 1 2 ap = 7 a = 6 7 8 9 10 1 6 7 8 9 10 b = 1 ap = 6 a = 6 7 8 9 10 6 7 8 9 10 b = 1×0 empty double row vector

3   Pass
a=[randperm(10) 3 5 7]; b=randperm(6)+1; y_correct=[1 3 5 7 8 9 10]; assert(isequal(new_setdiff(a,b),y_correct))

ap = 1 a = 3 7 6 1 9 2 4 10 8 3 5 7 b = 3 2 7 6 4 ap = 7 a = 3 7 6 1 9 2 10 8 3 5 7 b = 3 2 7 6 ap = 3 a = 3 7 1 9 2 10 8 3 5 7 b = 3 2 7 ap = 2 a = 3 1 9 2 10 8 3 5 7 b = 3 2 ap = 4 a = 3 1 9 10 8 3 5 7 b = 3 ap = 1 a = 1 9 10 8 3 5 7 b = 1×0 empty double row vector

4   Pass
a=[-5:5 -4:4]; b=[-4:4]; y_correct=[-5:5] assert(isequal(new_setdiff(a,b),y_correct))

y_correct = -5 -4 -3 -2 -1 0 1 2 3 4 5 ap = 10 a = -5 -4 -3 -2 -1 0 1 2 3 5 -4 -3 -2 -1 0 1 2 3 4 b = -4 -3 -2 -1 0 1 2 3 ap = 9 a = -5 -4 -3 -2 -1 0 1 2 5 -4 -3 -2 -1 0 1 2 3 4 b = -4 -3 -2 -1 0 1 2 ap = 8 a = -5 -4 -3 -2 -1 0 1 5 -4 -3 -2 -1 0 1 2 3 4 b = -4 -3 -2 -1 0 1 ap = 7 a = -5 -4 -3 -2 -1 0 5 -4 -3 -2 -1 0 1 2 3 4 b = -4 -3 -2 -1 0 ap = 6 a = -5 -4 -3 -2 -1 5 -4 -3 -2 -1 0 1 2 3 4 b = -4 -3 -2 -1 ap = 5 a = -5 -4 -3 -2 5 -4 -3 -2 -1 0 1 2 3 4 b = -4 -3 -2 ap = 4 a = -5 -4 -3 5 -4 -3 -2 -1 0 1 2 3 4 b = -4 -3 ap = 3 a = -5 -4 5 -4 -3 -2 -1 0 1 2 3 4 b = -4 ap = 2 a = -5 5 -4 -3 -2 -1 0 1 2 3 4 b = 1×0 empty double row vector

5   Pass
a=[2 2 2 2 3 3 5 7]; b=[2 2 2 2 3 3 5]; y_correct=8; assert(isequal(new_setdiff(a,b),y_correct-1))

ap = 7 a = 2 2 2 2 3 3 7 b = 2 2 2 2 3 3 ap = 5 a = 2 2 2 2 3 7 b = 2 2 2 2 3 ap = 5 a = 2 2 2 2 7 b = 2 2 2 2 ap = 1 a = 2 2 2 7 b = 2 2 2 ap = 1 a = 2 2 7 b = 2 2 ap = 1 a = 2 7 b = 2 ap = 1 a = 7 b = 1×0 empty double row vector