A double gutter in poker is when you have 2 gut shots to a straight.
For example, if the board is 268 and you have 45, a 3 (23456) or a 7 (45678) will complete a straight for you.
Given board[] and hand[], what’s an efficient algorithm for returning true if you have a double gutter and false if not?
Here’s an algorithm that can do this with bit vectors.
First, create a bit vector of 14 bits, say
cards(to include low and high ace) and set each bit for each element inhand[]andboard[].Next, generate 5 pairs of masks
(mask, gutter)for the first element inhand[]such that((cards & mask) ^ gutter)==0if you have a double gutter. E.g., if one of your cards is7, the(mask, gutter)pairs would be (assuming MSB->LSB order):I.e., you have 2 double gutters with 7 on either end and 3 with 7 in the middle.
Now, calculate
((cards & mask) ^ gutter)for each of the 5 pairs. If any is0you have a double gutter.EDIT: turns out you only need to test 5 masks.