The 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.
--------
Four of a kind is four cards of the same rank (column) and the highest other card as a 'kicker'. The columns represent A, 2, 3, ... K in the input. Aces are high.
This hand matrix:
0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 represents quads, so the return value from the function is TRUE.
This hand matrix does not:
0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 so the return value should be FALSE.
This hand matrix does represent quads
1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 Remember, hand matrices can contain any number of 1's from 0 to 52.
0 1 1 0 1 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 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 Would be FALSE for this function.
A second output argument should come from this function. It is a usedCards Matrix. It is of the same form as the hand Matrix, but it only shows the cards used to make the Quads plus kicker. If more than one Quads can be made, return the higher ranking one (Ace being the highest). If different suits are possible for the kicker, return the one higher up in the matrix.
Just checking, maybe I got this wrong but could you try adding this test?:
hm = [1 0 0 0 0 0 0 1 0 0 0 0 0
1 0 0 0 0 0 0 1 0 0 0 0 1
1 0 0 0 0 0 0 1 0 0 0 0 0
1 0 0 0 0 0 0 1 0 0 0 0 0];
y_correct.flag = true;
y_correct.usedCards = logical(...
[1 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0])
I believe several of the current solutions would fail that...
sorry, comments remove formatting, I meant:
hm = [1 0 0 0 0 0 0 1 0 0 0 0 0;1 0 0 0 0 0 0 1 0 0 0 0 1;1 0 0 0 0 0 0 1 0 0 0 0 0;1 0 0 0 0 0 0 1 0 0 0 0 0];
y_correct.flag = true;
y_correct.usedCards = logical([1 0 0 0 0 0 0 0 0 0 0 0 0;1 0 0 0 0 0 0 0 0 0 0 0 1;1 0 0 0 0 0 0 0 0 0 0 0 0;1 0 0 0 0 0 0 0 0 0 0 0 0])
Added the test case. Thank you for the addition.
Hi,
Why is test 3 not a quad? Is that a typo?
I think something is wrong with the test script.
not sure but this does not seem to consider Ace as the highest hand? (as it does for the kicker); the test suite does not discriminate...
281 Solvers
Project Euler: Problem 4, Palindromic numbers
101 Solvers
256 Solvers
Make a random, non-repeating vector.
621 Solvers
197 Solvers