Filter/identify characters within a cell array

1 Ansicht (letzte 30 Tage)
Ole Hansen
Ole Hansen am 5 Jul. 2012
Say you have a cell array:
cell_array={'Kh','8h','8d','Kd','Ks'}
where h=hearts, d=diamonds, s=spades. In poker, the given combination would correspond to a full house (i.e. a pair and a set).
How do I identify a full house and not a set, a pair or two pairs?
As of now, I identify a set by searching for 3 identical values, e.g. three kings:
idKings=cellfun(@(x)any(ismember('K',x)),cell_array);
if sum(idKings)==3;
...
end
but how do I apply rules such that a full house is identified, and not a pair, a set or two pairs?

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 5 Jul. 2012
Bearbeitet: Andrei Bobrov am 5 Jul. 2012
try this is code
value1 = cellfun(@(x)x(1),cell_array,'un',0);
[a,b,b] = unique(value1);
i1 = histc(b,1:max(b));
t = ismember(a,'K');
out = all(i1(t) == 3 & i1(~t) == 2);
  1 Kommentar
Ole Hansen
Ole Hansen am 5 Jul. 2012
Interesting. I havent thought about employing a histc. Thank you for the idea!
I thought that one could easily modify the "full house approach" to a simpiler case: two pair. However, it actually seems more difficult since one does not need to consider only 2 alike and 3 others alike, but rather 2 alike in two different pairs but also a third single value.
How does one identify these?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by