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.
--------
High Card is the five highest cards in your hand. It is basically what you have if you don't have anything else! The Ace (first column) is highest. The columns represent A, 2, 3, ... K. If the kickers also form a pair, it is still considered high card for the purposes of this function.
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 high card, so the return value from the function is TRUE.
This hand matrix does not (because it is defined as five cards):
0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
so the return value should be FALSE.
This hand matrix does represent a high card
0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0
Remember, hand matrices can contain any number of 1's from 0 to 52.
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0
Would be TRUE 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 high card. If more than one hag card can be made, return the higher ranking one (the one with the highest rank. Ace being the highest). If different suits are possible for the same high card, return the one higher up in the matrix, same for kickers. If the high card also happens to also be a four of a kind or full house, it still meets the defintion and should be returned.
Find the peak 3n+1 sequence value
852 Solvers
41 Solvers
Back to basics 20 - singleton dimensions
227 Solvers
Calculate the height of an object dropped from the sky
118 Solvers
Relative ratio of "1" in binary number
177 Solvers
Solution 48825
This solution doesn't work on R2015a or R2015b. It seems that the behavior of circshift is changed. For example, circshift(sparse(logical([1 2 3])),[0 1]) on R2015b returns all zeros.
Hi Peng, it seems that last major changes to circshift were introduced in 2014a (dim selection added). I'm not able to check this version, 2015a also returns falses. Anyway, (not) nice bug :).
Hi Jan, I don't have 2014a either. But I was able to check with 2013a available here: http://anycodes.cn (On the left hand side, you can select to run MATLAB). While circshift(sparse(logical([1 2 3])),[0 1]) and circshift(sparse(+logical([1 2 3])),[0 1]) produce different output on 2015a and 2015b, they give the same result (up to a class difference) on 2013a.
It's definitely a bug. It seems the newest version of circshift doesn't handle sparse logical matrices properly. It somehow changes trues to falses, but treat them like nonzeros. This leads to some funny logical properties because of the way the algorithms for sparse matrices work. Check following code: A = circshift(sparse([false false true false true]),[0 1]); A, nonzeros(A); full(A), A|1, A&1, ~A, xor(A,1), xor(A,0), and(A,A), or(A,A), A==~~A, isequal(A,~~A), isequal(A|0,A), %(etc.);
B = sparse([false false true false true]); B, B = B([end 1:end-1]), ...
This is my favourite:
C = circshift(sparse(true),1);
Haha, this is definitely a funny example to elaborate on the improper behavior of circshift/sparse when dealing with sparse logical matrix. I agree with you this is a bug, but still not very sure the bug is due to circshift or sparse. Maybe somebody can report this bug to MATHWORKS...