Cody

# Problem 1687. Poker Card Deal!

Solution 375637

Submitted on 27 Dec 2013 by Jean
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
%% people = 5; cardsDelt = 5; isJokerIn = 0; [dealtDeck, deckLeftover] = Poker_Deal(people ,cardsDelt ,isJokerIn) deckCheck = {'2h'; '3h'; '4h'; '5h'; '6h'; '7h'; '8h'; '9h'; '10h'; 'jh'; 'qh'; 'kh'; 'ah'; '2d'; '3d'; '4d'; '5d'; '6d'; '7d'; '8d'; '9d'; '10d'; 'jd'; 'qd'; 'kd'; 'ad'; '2s'; '3s'; '4s'; '5s'; '6s'; '7s'; '8s'; '9s'; '10s'; 'js'; 'qs'; 'ks'; 'as'; '2c'; '3c'; '4c'; '5c'; '6c'; '7c'; '8c'; '9c'; '10c'; 'jc'; 'qc'; 'kc'; 'ac'} h = (sum(sum(ismember(deckCheck,dealtDeck))) == 25) & ~issorted(reshape(dealtDeck,25,1)); g = (sum(ismember(deckCheck,deckLeftover)) == (52-25)) & ~issorted(deckLeftover); y_correct = g&h; assert(isequal(g,h))

hands = '7s' '7h' '3s' 'qh' '10c' '10s' '9h' 'ac' '8c' 'as' '4h' 'js' '8h' 'qc' 'jd' '4d' '2s' 'jc' '7c' 'qd' '3h' '9s' 'kc' '5d' '6h' ans = 'qs' 'ks' 'kh' 'kd' 'jh' 'ah' 'ad' '9d' '9c' '8s' '8d' '7d' '6s' '6d' '6c' '5s' '5h' '5c' '4s' '4c' '3d' '3c' '2h' '2d' '2c' '10h' '10d' dealtDeck = '7s' '7h' '3s' 'qh' '10c' '10s' '9h' 'ac' '8c' 'as' '4h' 'js' '8h' 'qc' 'jd' '4d' '2s' 'jc' '7c' 'qd' '3h' '9s' 'kc' '5d' '6h' deckLeftover = 'qs' 'ks' 'kh' 'kd' 'jh' 'ah' 'ad' '9d' '9c' '8s' '8d' '7d' '6s' '6d' '6c' '5s' '5h' '5c' '4s' '4c' '3d' '3c' '2h' '2d' '2c' '10h' '10d' deckCheck = '2h' '3h' '4h' '5h' '6h' '7h' '8h' '9h' '10h' 'jh' 'qh' 'kh' 'ah' '2d' '3d' '4d' '5d' '6d' '7d' '8d' '9d' '10d' 'jd' 'qd' 'kd' 'ad' '2s' '3s' '4s' '5s' '6s' '7s' '8s' '9s' '10s' 'js' 'qs' 'ks' 'as' '2c' '3c' '4c' '5c' '6c' '7c' '8c' '9c' '10c' 'jc' 'qc' 'kc' 'ac'

2   Pass
%% people = 3; cardsDelt = 5; isJokerIn = 0; [dealtDeck, deckLeftover] = Poker_Deal(people ,cardsDelt ,isJokerIn) deckCheck = {'2h'; '3h'; '4h'; '5h'; '6h'; '7h'; '8h'; '9h'; '10h'; 'jh'; 'qh'; 'kh'; 'ah'; '2d'; '3d'; '4d'; '5d'; '6d'; '7d'; '8d'; '9d'; '10d'; 'jd'; 'qd'; 'kd'; 'ad'; '2s'; '3s'; '4s'; '5s'; '6s'; '7s'; '8s'; '9s'; '10s'; 'js'; 'qs'; 'ks'; 'as'; '2c'; '3c'; '4c'; '5c'; '6c'; '7c'; '8c'; '9c'; '10c'; 'jc'; 'qc'; 'kc'; 'ac'} h = (sum(sum(ismember(deckCheck,dealtDeck))) == 15) & ~issorted(reshape(dealtDeck,15,1)); g = (sum(ismember(deckCheck,deckLeftover)) == (52-15)) & ~issorted(deckLeftover); y_correct = g&h; assert(isequal(g,h))

hands = '7d' 'qs' 'as' '10d' '7h' 'kh' '4c' '3h' '6s' '9s' 'kc' 'jc' '5d' '2d' 'ks' ans = 'qh' 'qd' 'qc' 'kd' 'js' 'jh' 'jd' 'ah' 'ad' 'ac' '9h' '9d' '9c' '8s' '8h' '8d' '8c' '7s' '7c' '6h' '6d' '6c' '5s' '5h' '5c' '4s' '4h' '4d' '3s' '3d' '3c' '2s' '2h' '2c' '10s' '10h' '10c' dealtDeck = '7d' 'qs' 'as' '10d' '7h' 'kh' '4c' '3h' '6s' '9s' 'kc' 'jc' '5d' '2d' 'ks' deckLeftover = 'qh' 'qd' 'qc' 'kd' 'js' 'jh' 'jd' 'ah' 'ad' 'ac' '9h' '9d' '9c' '8s' '8h' '8d' '8c' '7s' '7c' '6h' '6d' '6c' '5s' '5h' '5c' '4s' '4h' '4d' '3s' '3d' '3c' '2s' '2h' '2c' '10s' '10h' '10c' deckCheck = '2h' '3h' '4h' '5h' '6h' '7h' '8h' '9h' '10h' 'jh' 'qh' 'kh' 'ah' '2d' '3d' '4d' '5d' '6d' '7d' '8d' '9d' '10d' 'jd' 'qd' 'kd' 'ad' '2s' '3s' '4s' '5s' '6s' '7s' '8s' '9s' '10s' 'js' 'qs' 'ks' 'as' '2c' '3c' '4c' '5c' '6c' '7c' '8c' '9c' '10c' 'jc' 'qc' 'kc' 'ac'

3   Pass
%% people = 4; cardsDelt = 7; isJokerIn = 0; [dealtDeck, deckLeftover] = Poker_Deal(people ,cardsDelt ,isJokerIn) deckCheck = {'2h'; '3h'; '4h'; '5h'; '6h'; '7h'; '8h'; '9h'; '10h'; 'jh'; 'qh'; 'kh'; 'ah'; '2d'; '3d'; '4d'; '5d'; '6d'; '7d'; '8d'; '9d'; '10d'; 'jd'; 'qd'; 'kd'; 'ad'; '2s'; '3s'; '4s'; '5s'; '6s'; '7s'; '8s'; '9s'; '10s'; 'js'; 'qs'; 'ks'; 'as'; '2c'; '3c'; '4c'; '5c'; '6c'; '7c'; '8c'; '9c'; '10c'; 'jc'; 'qc'; 'kc'; 'ac'} h = (sum(sum(ismember(deckCheck,dealtDeck))) == 28) & ~issorted(reshape(dealtDeck,28,1)); g = (sum(ismember(deckCheck,deckLeftover)) == (52-28)) & ~issorted(deckLeftover); y_correct = g&h; assert(isequal(g,h))

hands = 'jh' '5h' 'qs' 'js' '10c' '9d' 'qc' '6c' 'ah' '2s' '2h' '2c' 'qd' '6d' 'kc' '5d' '3d' '7h' '6h' '3h' 'as' '2d' '9s' '8s' '7c' '10s' 'ac' '3c' ans = 'qh' 'ks' 'kh' 'kd' 'jd' 'jc' 'ad' '9h' '9c' '8h' '8d' '8c' '7s' '7d' '6s' '5s' '5c' '4s' '4h' '4d' '4c' '3s' '10h' '10d' dealtDeck = 'jh' '5h' 'qs' 'js' '10c' '9d' 'qc' '6c' 'ah' '2s' '2h' '2c' 'qd' '6d' 'kc' '5d' '3d' '7h' '6h' '3h' 'as' '2d' '9s' '8s' '7c' '10s' 'ac' '3c' deckLeftover = 'qh' 'ks' 'kh' 'kd' 'jd' 'jc' 'ad' '9h' '9c' '8h' '8d' '8c' '7s' '7d' '6s' '5s' '5c' '4s' '4h' '4d' '4c' '3s' '10h' '10d' deckCheck = '2h' '3h' '4h' '5h' '6h' '7h' '8h' '9h' '10h' 'jh' 'qh' 'kh' 'ah' '2d' '3d' '4d' '5d' '6d' '7d' '8d' '9d' '10d' 'jd' 'qd' 'kd' 'ad' '2s' '3s' '4s' '5s' '6s' '7s' '8s' '9s' '10s' 'js' 'qs' 'ks' 'as' '2c' '3c' '4c' '5c' '6c' '7c' '8c' '9c' '10c' 'jc' 'qc' 'kc' 'ac'

4   Pass
%% people = 5; cardsDelt = 6; isJokerIn = 1; [dealtDeck, deckLeftover] = Poker_Deal(people ,cardsDelt ,isJokerIn) deckCheck = {'2h'; '3h'; '4h'; '5h'; '6h'; '7h'; '8h'; '9h'; '10h'; 'jh'; 'qh'; 'kh'; 'ah'; '2d'; '3d'; '4d'; '5d'; '6d'; '7d'; '8d'; '9d'; '10d'; 'jd'; 'qd'; 'kd'; 'ad'; '2s'; '3s'; '4s'; '5s'; '6s'; '7s'; '8s'; '9s'; '10s'; 'js'; 'qs'; 'ks'; 'as'; '2c'; '3c'; '4c'; '5c'; '6c'; '7c'; '8c'; '9c'; '10c'; 'jc'; 'qc'; 'kc'; 'ac'; 'J'; 'J'} h = (sum(sum(ismember(deckCheck,dealtDeck))) == 30) & ~issorted(reshape(dealtDeck,30,1)); g = (sum(ismember(deckCheck,deckLeftover)) == (54-30)) & ~issorted(deckLeftover); y_correct = g&h; assert(isequal(g,h))

hands = '9c' '5h' 'jh' 'qh' '3h' '10d' 'kd' '8h' '8c' '6d' '2h' '2s' '4d' '9d' 'jc' 'kc' '9s' '8d' '6c' 'js' '3c' '6s' '5c' 'ad' 'qc' 'J' 'jd' 'kh' '5d' '2c' ans = 'qs' 'qd' 'ks' 'as' 'ah' 'ac' '9h' '8s' '7s' '7h' '7d' '7c' '6h' '5s' '4s' '4h' '4c' '3s' '3d' '2d' '10s' '10h' '10c' dealtDeck = '9c' '5h' 'jh' 'qh' '3h' '10d' 'kd' '8h' '8c' '6d' '2h' '2s' '4d' '9d' 'jc' 'kc' '9s' '8d' '6c' 'js' '3c' '6s' '5c' 'ad' 'qc' 'J' 'jd' 'kh' '5d' '2c' deckLeftover = 'qs' 'qd' 'ks' 'as' 'ah' 'ac' '9h' '8s' '7s' '7h' '7d' '7c' '6h' '5s' '4s' '4h' '4c' '3s' '3d' '2d' '10s' '10h' '10c' deckCheck = '2h' '3h' '4h' '5h' '6h' '7h' '8h' '9h' '10h' 'jh' 'qh' 'kh' 'ah' '2d' '3d' '4d' '5d' '6d' '7d' '8d' '9d' '10d' 'jd' 'qd' 'kd' 'ad' '2s' '3s' '4s' '5s' '6s' '7s' '8s' '9s' '10s' 'js' 'qs' 'ks' 'as' '2c' '3c' '4c' '5c' '6c' '7c' '8c' '9c' '10c' 'jc' 'qc' 'kc' 'ac' 'J' 'J'

5   Pass
%% people = 3; cardsDelt = 4; isJokerIn = 1; [dealtDeck, deckLeftover] = Poker_Deal(people ,cardsDelt ,isJokerIn) deckCheck = {'2h'; '3h'; '4h'; '5h'; '6h'; '7h'; '8h'; '9h'; '10h'; 'jh'; 'qh'; 'kh'; 'ah'; '2d'; '3d'; '4d'; '5d'; '6d'; '7d'; '8d'; '9d'; '10d'; 'jd'; 'qd'; 'kd'; 'ad'; '2s'; '3s'; '4s'; '5s'; '6s'; '7s'; '8s'; '9s'; '10s'; 'js'; 'qs'; 'ks'; 'as'; '2c'; '3c'; '4c'; '5c'; '6c'; '7c'; '8c'; '9c'; '10c'; 'jc'; 'qc'; 'kc'; 'ac'; 'J'; 'J'} h = (sum(sum(ismember(deckCheck,dealtDeck))) == 12) & ~issorted(reshape(dealtDeck,12,1)); g = (sum(ismember(deckCheck,deckLeftover)) == (54-12)) & ~issorted(deckLeftover); y_correct = g&h; assert(isequal(g,h))

hands = '3s' '4h' 'jd' '2h' '8h' '7d' '8c' '5c' 'ac' '7h' '2c' '3c' ans = 'qs' 'qh' 'qd' 'qc' 'ks' 'kh' 'kd' 'kc' 'js' 'jh' 'jc' 'as' 'ah' 'ad' 'J' '9s' '9h' '9d' '9c' '8s' '8d' '7s' '7c' '6s' '6h' '6d' '6c' '5s' '5h' '5d' '4s' '4d' '4c' '3h' '3d' '2s' '2d' '10s' '10h' '10d' '10c' dealtDeck = '3s' '4h' 'jd' '2h' '8h' '7d' '8c' '5c' 'ac' '7h' '2c' '3c' deckLeftover = 'qs' 'qh' 'qd' 'qc' 'ks' 'kh' 'kd' 'kc' 'js' 'jh' 'jc' 'as' 'ah' 'ad' 'J' '9s' '9h' '9d' '9c' '8s' '8d' '7s' '7c' '6s' '6h' '6d' '6c' '5s' '5h' '5d' '4s' '4d' '4c' '3h' '3d' '2s' '2d' '10s' '10h' '10d' '10c' deckCheck = '2h' '3h' '4h' '5h' '6h' '7h' '8h' '9h' '10h' 'jh' 'qh' 'kh' 'ah' '2d' '3d' '4d' '5d' '6d' '7d' '8d' '9d' '10d' 'jd' 'qd' 'kd' 'ad' '2s' '3s' '4s' '5s' '6s' '7s' '8s' '9s' '10s' 'js' 'qs' 'ks' 'as' '2c' '3c' '4c' '5c' '6c' '7c' '8c' '9c' '10c' 'jc' 'qc' 'kc' 'ac' 'J' 'J'

6   Pass
%% people = 3; cardsDelt = 3; isJokerIn = 1; [dealtDeck, deckLeftover] = Poker_Deal(people ,cardsDelt ,isJokerIn) deckCheck = {'2h'; '3h'; '4h'; '5h'; '6h'; '7h'; '8h'; '9h'; '10h'; 'jh'; 'qh'; 'kh'; 'ah'; '2d'; '3d'; '4d'; '5d'; '6d'; '7d'; '8d'; '9d'; '10d'; 'jd'; 'qd'; 'kd'; 'ad'; '2s'; '3s'; '4s'; '5s'; '6s'; '7s'; '8s'; '9s'; '10s'; 'js'; 'qs'; 'ks'; 'as'; '2c'; '3c'; '4c'; '5c'; '6c'; '7c'; '8c'; '9c'; '10c'; 'jc'; 'qc'; 'kc'; 'ac'; 'J'; 'J'} h = (sum(sum(ismember(deckCheck,dealtDeck))) == 9) & ~issorted(reshape(dealtDeck,9,1)); g = (sum(ismember(deckCheck,deckLeftover)) == (54-9)) & ~issorted(deckLeftover); y_correct = g&h; assert(isequal(g,h))

hands = '6d' 'ks' '5d' '3h' 'jh' '5h' '7h' 'J' '10c' ans = 'qs' 'qh' 'qd' 'qc' 'kh' 'kd' 'kc' 'js' 'jd' 'jc' 'as' 'ah' 'ad' 'ac' '9s' '9h' '9d' '9c' '8s' '8h' '8d' '8c' '7s' '7d' '7c' '6s' '6h' '6c' '5s' '5c' '4s' '4h' '4d' '4c' '3s' '3d' '3c' '2s' '2h' '2d' '2c' '10s' '10h' '10d' dealtDeck = '6d' 'ks' '5d' '3h' 'jh' '5h' '7h' 'J' '10c' deckLeftover = 'qs' 'qh' 'qd' 'qc' 'kh' 'kd' 'kc' 'js' 'jd' 'jc' 'as' 'ah' 'ad' 'ac' '9s' '9h' '9d' '9c' '8s' '8h' '8d' '8c' '7s' '7d' '7c' '6s' '6h' '6c' '5s' '5c' '4s' '4h' '4d' '4c' '3s' '3d' '3c' '2s' '2h' '2d' '2c' '10s' '10h' '10d' deckCheck = '2h' '3h' '4h' '5h' '6h' '7h' '8h' '9h' '10h' 'jh' 'qh' 'kh' 'ah' '2d' '3d' '4d' '5d' '6d' '7d' '8d' '9d' '10d' 'jd' 'qd' 'kd' 'ad' '2s' '3s' '4s' '5s' '6s' '7s' '8s' '9s' '10s' 'js' 'qs' 'ks' 'as' '2c' '3c' '4c' '5c' '6c' '7c' '8c' '9c' '10c' 'jc' 'qc' 'kc' 'ac' 'J' 'J'

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!