#๐Ÿ”’ full house - how can I determine high card in 3 of a kind?

63 messages ยท Page 1 of 1 (latest)

spare bear
#

as in title how can I determine high card in 3 of a kind
for example 22288, 44433

neon archBOT
#

@spare bear

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

spare bear
#

determining just high card its easy

#

but I need restriction here

#

so would be same logic for rank of 3 of a kind

#

I thought also about sum cards in three of a kind

#

2+2+2, 4+4+4

#

but maybe high card in 3 of a kind better option

#

of course poker game texas holdem

#

I think I found solution it depends on position in hand so I can just hardcode highcard from index 0

#

so if 22288
then
value = hand[0]
in pseudocode

#

and elif 88222
then
value = hand[2]

#

I think โœ… solved

vapid ember
#

your question unfortunately is no good to someone who doesn't know the terminology you're using... for me, I can't help because I don't know what a 'high card' is

#

I thought it was the highest of the spare cards (not the 3 from the fuller part of the house)

spare bear
#

so high card is with higher value

#

for example A is higher than K

vapid ember
#

so all you're doing is looking for the highest value of all 5 cards?

spare bear
#

no not in 5 cards but subset of it

#

not like in case of two pair when you look at 5 ards to determine for example last card is high card

#

example 55JJA

#

and A is high card

vapid ember
#

I get the 'full house' - 3 cards of one value and 2 of another.
but when do you look at 'high card'? does a full house have a 'high card' or is this something entirely separate?

spare bear
#

full house so 3 of a kind and pair

vapid ember
#

yep, 3 of one value and 2 of another, that's the only part I understand. sorry ๐Ÿ™‚

spare bear
#

yes I need to determine high card in 3 of a kind so for example 22288, 44433
so it will be respectively 2 and 4

vapid ember
#

from what you said here:

value = hand[0]
in pseudocode
and elif 88222
then
value = hand[2]
it looks like you are just trying to get the value of the 3 of a kind card?

spare bear
#

no I grab high card maybe in this way

#

its ok

#

ah yes right

vapid ember
#

I'm sure regex would have a good solution, otherwise perhaps:

from collections import Counter
print(Counter("44433").most_common())
# output: [('4', 3), ('3', 2)]
woeful shard
#

ranking hands may become easier if you rearrange the cards first

spare bear
#

so sort them

#

yes because I could have 28822 etc

vapid ember
#

I grouped them using a Counter, but yeah sorting on the value alone doesn't help? your 28822 could be 22288 or 88222 depending on sorting order, which isn't helpful because you still haven't identified the 3 of a kind

spare bear
#

so it must some custom sorting if I want 3 of a kind and pair

#

but in this case I have 2 cases

#

like I above typed

#

if and elif

#

22288 and 88222

#

but its same

#

2's over 8's

vapid ember
#

yeah, it's the same set of cards but you still haven't found the value of the 3 of a kind. My Counter does that.

spare bear
#

yes I will use it thanks

vapid ember
#

I imagine if you have a bunch of different possibilities (ie more than just full house) that regex might be the better option. Several regex patterns that act on the sorted card string and produce what you want.

spare bear
#

hmm but I dont have string I have list of tuples

vapid ember
#

You gave a string as your example... but still, a string could be easily gathered. A string is an iterable just like a list or tuple.

spare bear
#

yes sorry

#

Counter works on iterable not strings only?

vapid ember
#
class Counter(builtins.dict)
 |  Counter(iterable=None, /, **kwds)
 |
 |  Dict subclass for counting hashable items.  Sometimes called a bag
 |  or multiset.  Elements are stored as dictionary keys and their counts
 |  are stored as dictionary values.
spare bear
#

ok

vapid ember
#
In [8]: Counter((1,2,3,3))
Out[8]: Counter({1: 1, 2: 1, 3: 2})
spare bear
#

ah its bag, multiset

vapid ember
#

eh?

spare bear
#

I mean result or output

#

yes so shows frequency

vapid ember
#

That's the representation of it, but yeah it is a subclass of Dict.
It has methods that will output other formats, like .most_common() does

spare bear
#

ok I start with high card and back to full house

#

it helped

vapid ember
#

Otherwise you might be looking at something like this which would return None if not full house else the value of the 3 card set

import re

def get_three_of_a_kind_value(hand_string):
    # Sort the string to ensure it's in order
    sorted_hand = ''.join(sorted(hand_string))
    
    # Define the regex pattern for a full house
    pattern = r'^(.)\1{2}(.)\2$|^(.)\3(.)\4{2}$'
    
    # Match the pattern against the sorted hand
    match = re.match(pattern, sorted_hand)
    
    # If there's a match, return the three-of-a-kind value
    if match:
        # Check which part of the regex matched
        if match.group(1):
            # The first group is the three-of-a-kind when the pattern matches the first option
            return match.group(1)
        else:
            # The fourth group is the three-of-a-kind when the pattern matches the second option
            return match.group(4)
    
    return None

# Example usage
hand_string = "AKAKK"  # Sorting this gives "AAKKK"
three_of_a_kind_value = get_three_of_a_kind_value(hand_string)
print(f"The three of a kind is: {three_of_a_kind_value}")
#

I've got to shuffle on to something else, good luck with it.

neon archBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.