View Single Post
Old 2012-02-08, 11:20   #2
axn
 
axn's Avatar
 
Jun 2003

7×683 Posts
Default

Use a bit-based approach.

Let x be an integer variable. For each of the 7 cards, set x = x | (1 << card_value)

Now we need to check if the bit representation of x has 5 consecutive '1' bits.

Check if the expression x & (x << 1) & (x << 2) & (x << 3) & (x << 4) is non-zero. If so, it has 5 consecutive 1's.

Last fiddled with by axn on 2012-02-08 at 11:24
axn is offline   Reply With Quote