Joker
card, which can be used in
place of any other card. As a result, we cannot use a notion of binary
equivalence of two cards, which would not be transitive. Instead, we define
an asymmetric relation agrees_with
: for instance, the card Joker
agrees with King
, but not the converse. For convenience, we also
define the relation disagree_with
, which is the negation of the
symmetric relation agrees_with
.
|
find_similar
that searches
sets of k
similar cards among a hand
. This function is defined
by induction. If the hand
is empty, there is no solution. If the
first element of the hand
is a Joker
, we search for sets of
k
-1
similar elements in the rest of the hand
and add the
Joker
in front of each set. Otherwise, the first element of
hand
is a regular card h
: we first search for the set of all
elements matching the card h
in the rest of the hand; this set
constitutes a solution if its size if at least k
; then, we add all
other solutions among the rest of the hand that disagree with h
.
Otherwise, the solutions are only those that disagree with h
.
|
| |||
|