Compare two hands:
NB. x and y are 5-card hands (rank only), result is 1 if x is low, _1 if
y is low, 0 if tie
lowerhand =: {.@(/:@|. - /:)@(,:&(\:~)&(,.~ #\ - i.~)&(/:~))
NB. sort ranks in order
NB. (#\ - i.~) trick to convert each card to (ordinal # among cards of
same rank,rank)
NB. sort descending to look at high card first
NB. join the two hands into an array (2x2x5) of hands
NB. compare using grade: +1 if y is higher/=, -1 if x is higher/=, add
to get result
8 7 1 3 2 lowerhand 1 3 2 4 7
_1
8 7 1 3 2 lowerhand 1 3 2 1 7
1
Henry Rich
On 5/10/2021 5:44 PM, 'Pascal Jasmin' via Programming wrote:
This is about scoring poker hands in general, and just lowest score wins.
leaving out the logic for scoring pair or higher hands, sorting the hand in
ascending order, and then appending all missing card (units 1-13) in ascending
order, lets you use A. (anagram) to score the hand.
A. 9 10 11 12 13 1 2 3 4 5 6 7 8
4183603200
A. 8 10 11 12 13 1 2 3 4 5 6 7 9
3704601600
above compares king high straight to an 8 replacement for the 9. Lowest
anagram wins.
A. 0 1 2 3 4 5 6 7 8 9 10 11 12 13
0
A. 0 1 2 3 4 6 5 7 8 9 10 11 12 13
40320
A. 0 1 2 3 4 7 6 5 8 9 10 11 12 13
85680
On Sunday, May 9, 2021, 03:43:32 p.m. EDT, Devon McCormick <[email protected]>
wrote:
I'm working on some code to work with low poker hands (as in a game like
Omaha or lowball). Since not everyone is familiar with this domain, I've
put together a wiki page outlining what this means and the code I have so
far: https://code.jsoftware.com/wiki/User:Devon_McCormick/Poker/Lowball .
This may be part of the NYCJUG meeting (
https://www.meetup.com/J-Dynamic-Functional-Programming/) in a few days, so
any suggestions are welcome.
Thanks!
--
This email has been checked for viruses by AVG.
https://www.avg.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm