Hi everyone,
I’m having a problem where i’m trying to make a function that returns if a poker hand contains exactly one pair. The first code works for a hand of four, but gives an incorrent return for a hand of 5.
pairQ[{x_, x_, y_, y_} /; x != y] := False; (* two pair*)
pairQ[{___, x_, x_, x_}] := False; (* three of a kind *)
pairQ[{___, x_, x_,}] := True; (* one pair *)
pairQ[{___}] := False (* something else...*)
hand = {2, 3, 4, 4};
pairQ[hand]
This will output true since 4 and 4 is the same.
pairQ[{___, x_, x_, ___, y_, ___, y_, ___} /; x != y] := False; (* two pair*)
pairQ[{_, x_, x_, x_, _}] := False; (* three of a kind *)
pairQ[{___, x_, x_, ___}] := True; (* one pair *)
pairQ[{___}] := False (* something else...*)
hand = {2, 2, 3, 4, 4};
pairQ[hand]
This returns true, why? As I interpreted the number of blankspaces indiciate how many elements that can sit at that position. Eg _ = only one element can take its place. __ = 2 and ___= 3 or more. Can anyone help me with this?