How to check if an array contains a "Full House"?

Godot Version

4.2.2

Question

How do I check if array has 2 values the same and 3 values different from the first two values but they themselves are the same?

Examples:
[4, 4, 7, 7, 7] would return true
[1, 3, 3, 3, 1] would return true
[2, 1, 6, 6, 6] would return false

Assuming 5 elements…

Sort the array.  
if element[0] == element[4]:  
   you get here if you have a 5 of a kind. 
elIf element [0] == element [2]:   
   if element[3] == element[4]: 
       you get here if you have a full house
elif element[0] == element[1]:  
   if element[2] == element[4]:  
      you get here if you have a full house
1 Like

a full hand is a hand that should only have 2 unique cards.

var example_hand = [2, 1, 6, 6, 6]

func is_full_house(hand: Array) -> bool:
    var uniques = []

    for card in hand:
        if not uniques.has(card):
            uniques.append(card)

return uniques.size() == 2

You could probably also use the dizzy method which saves 17% compute time

func is_full_house(hand: Array) -> bool:
	var dict := {}
	for num in hand: dict[num] = 1
	return dict.keys().size() == 2