MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayThe Poker Series consists of many short, well defined functions that when combined will lead to complex behavior. Our goal is to create a function that will take two hand matrices (defined below) and return the winning hand.

A hand matrix is 4x13 binary matrix showing the cards that are available for a poker player to use. This program will be expandable to use 5 card hands through 52 card hands! Suits of the cards are all equally ranked, so they only matter for determination of flushes (and straight flushes).

For each challenge, you should feel free to reuse your solutions from prior challenges in the series. To break this problem into smaller pieces, I am likely making architectural choices that are sub-optimal for speed. This is being done as an exercise in coding. The larger goal of this project can likely be done in a much faster, but more obscure way.

--------

Find the best hand using the definitions from earlier in this series.

out.code is:

- Straight Flush
- Quads
- Full House
- Flush
- Straight
- Three of a kind
- Two pair
- Pair
- High Card
- No valid Hand

out.cardsUsed is the same as is returned from the functions defined earlier for each type of hand.

This hand matrix:

0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0

represents a three of a kind, so the return code is 6.

30 correct solutions
24 incorrect solutions

Last solution submitted on Jul 07, 2014

1 player likes this problem

2 Comments

Jan Orwat
on 13 Mar 2014

it won't work properly if hm=[0 1 0 1 0 0 0 0 0 0 0 0 0; 0 1 0 1 0 0 0 0 0 0 0 0 0; 0 1 0 1 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0 0 0]; it says that it is a Three of a kind, but it is a Full House actually.

Yaroslav
on 8 May 2014

Thank you, @Yan_Orwat; I have repaired the solution.

3 Comments