




from __future__ import annotations

import os







class 		__UpperCAmelCase:





     """simple docstring"""



     __UpperCAmelCase	: Optional[Any]						=    (
         """High card""",
         """One pair""",
         """Two pairs""",
         """Three of a kind""",
         """Straight""",
         """Flush""",
         """Full house""",
         """Four of a kind""",
         """Straight flush""",
         """Royal flush""",
     )

     __UpperCAmelCase	: int						=    (
         """""",  # placeholder as tuples are zero-indexed
         """One""",
         """Two""",
         """Three""",
         """Four""",
         """Five""",
         """Six""",
         """Seven""",
         """Eight""",
         """Nine""",
         """Ten""",
         """Jack""",
         """Queen""",
         """King""",
         """Ace""",
     )

     def __init__(      self :       Optional[int]						,				A :       str    )			->			None:






         """simple docstring"""
         if not isinstance(A						,				A    ):
             a__      =       f"""Hand should be of type 'str': {hand!r}"""
             raise TypeError(A    )
         # split removes duplicate whitespaces so no need of strip
         if len(hand.split(""" """    )    ) != 5:
             a__      =       f"""Hand should contain only 5 cards: {hand!r}"""
             raise ValueError(A    )
         a__      =       hand
         a__      =       0
         a__      =       0
         a__ ,		a__      =       self._internal_state()
         a__      =       self._get_hand_type()
         a__      =       self._card_values[0]

     @property
     def 				__SCREAMING_SNAKE_CASE		(      self :       Optional[Any]    )			->			str:






         """simple docstring"""
         return self._hand

     def 				__SCREAMING_SNAKE_CASE		(      self :       Optional[Any]						,				A :       PokerHand    )			->			str:






         """simple docstring"""
         # Breaking the tie works on the following order of precedence:
         # 1. First pair (default 0)
         # 2. Second pair (default 0)
         # 3. Compare all cards in reverse order because they are sorted.

         # First pair and second pair will only be a non-zero value if the card
         # type is either from the following:
         # 21: Four of a kind
         # 20: Full house
         # 17: Three of a kind
         # 16: Two pairs
         # 15: One pair
         if self._hand_type > other._hand_type:
             return "Win"
         elif self._hand_type < other._hand_type:
             return "Loss"
         elif self._first_pair == other._first_pair:
             if self._second_pair == other._second_pair:
                 return self._compare_cards(A    )
             else:
                 return "Win" if self._second_pair > other._second_pair else "Loss"
         return "Win" if self._first_pair > other._first_pair else "Loss"

     def 				__SCREAMING_SNAKE_CASE		(      self :       Optional[Any]    )			->			str:






         """simple docstring"""
         a__      =       PokerHand._HAND_NAME[self._hand_type - 14]
         a__      =       PokerHand._CARD_NAME[self._high_card]
         a__      =       PokerHand._CARD_NAME[self._first_pair]
         a__      =       PokerHand._CARD_NAME[self._second_pair]
         if self._hand_type in [22, 19, 18]:
             return name + f""", {high}-high"""
         elif self._hand_type in [21, 17, 15]:
             return name + f""", {paira}s"""
         elif self._hand_type in [20, 16]:
             a__      =       """over""" if self._hand_type == 20 else """and"""
             return name + f""", {paira}s {join} {paira}s"""
         elif self._hand_type == 23:
             return name
         else:
             return name + f""", {high}"""

     def 				__SCREAMING_SNAKE_CASE		(      self :       List[str]						,				A :       PokerHand    )			->			str:






         """simple docstring"""
         # Enumerate gives us the index as well as the element of a list
         for index, card_value in enumerate(self._card_values    ):
             if card_value != other._card_values[index]:
                 return "Win" if card_value > other._card_values[index] else "Loss"
         return "Tie"

     def 				__SCREAMING_SNAKE_CASE		(      self :       Optional[int]    )			->			int:






         """simple docstring"""
         # Number representing the type of hand internally:
         # 23: Royal flush
         # 22: Straight flush
         # 21: Four of a kind
         # 20: Full house
         # 19: Flush
         # 18: Straight
         # 17: Three of a kind
         # 16: Two pairs
         # 15: One pair
         # 14: High card
         if self._is_flush():
             if self._is_five_high_straight() or self._is_straight():
                 return 23 if sum(self._card_values    ) == 60 else 22
             return 19
         elif self._is_five_high_straight() or self._is_straight():
             return 18
         return 14 + self._is_same_kind()

     def 				__SCREAMING_SNAKE_CASE		(      self :       Union[str, Any]    )			->			bool:






         """simple docstring"""
         return len(self._card_suit    ) == 1

     def 				__SCREAMING_SNAKE_CASE		(      self :       Dict    )			->			bool:






         """simple docstring"""
         # If a card is a five high straight (low ace) change the location of
         # ace from the start of the list to the end. Check whether the first
         # element is ace or not. (Don't want to change again)
         # Five high straight (low ace): AH 2H 3S 4C 5D
         # Why use sorted here? One call to this function will mutate the list to
         # [5, 4, 3, 2, 14] and so for subsequent calls (which will be rare) we
         # need to compare the sorted version.
         # Refer test_multiple_calls_five_high_straight in test_poker_hand.py
         if sorted(self._card_values    ) == [2, 3, 4, 5, 14]:
             if self._card_values[0] == 14:
                 # Remember, our list is sorted in reverse order
                 a__      =       self._card_values.pop(0    )
                 self._card_values.append(A    )
             return True
         return False

     def 				__SCREAMING_SNAKE_CASE		(      self :       Union[str, Any]    )			->			bool:






         """simple docstring"""
         for i in range(4    ):
             if self._card_values[i] - self._card_values[i + 1] != 1:
                 return False
         return True

     def 				__SCREAMING_SNAKE_CASE		(      self :       Optional[int]    )			->			int:






         """simple docstring"""
         # Kind Values for internal use:
         # 7: Four of a kind
         # 6: Full house
         # 3: Three of a kind
         # 2: Two pairs
         # 1: One pair
         # 0: False
         a__      =       a__      =       a__      =       0
         for i in range(4    ):
             # Compare two cards at a time, if they are same increase 'kind',
             # add the value of the card to val1, if it is repeating again we
             # will add 2 to 'kind' as there are now 3 cards with same value.
             # If we get card of different value than val1, we will do the same
             # thing with val2
             if self._card_values[i] == self._card_values[i + 1]:
                 if not vala:
                     a__      =       self._card_values[i]
                     kind += 1
                 elif vala == self._card_values[i]:
                     kind += 2
                 elif not vala:
                     a__      =       self._card_values[i]
                     kind += 1
                 elif vala == self._card_values[i]:
                     kind += 2
        # For consistency in hand type (look at note in _get_hand_type function)
         a__      =       kind + 2 if kind in [4, 5] else kind
         # first meaning first pair to compare in 'compare_with'
         a__      =       max(A						,				A    )
         a__      =       min(A						,				A    )
         # If it's full house (three count pair + two count pair), make sure
         # first pair is three count and if not then switch them both.
         if kind == 6 and self._card_values.count(A    ) != 3:
             a__ ,		a__      =       second, first
         a__      =       first
         a__      =       second
         return kind

     def 				__SCREAMING_SNAKE_CASE		(      self :       Dict    )			->			tuple[list[int], set[str]]:






         """simple docstring"""
         # Internal representation of hand as a list of card values and
         # a set of card suit
         a__      =       {"T": "10", "J": "11", "Q": "12", "K": "13", "A": "14"}
         a__      =       self._hand.translate(str.maketrans(A    )    ).split()
         a__      =       [int(card[:-1]    ) for card in new_hand]
         a__      =       {card[-1] for card in new_hand}
         return sorted(A						,				reverse=A    ), card_suit

     def __repr__(      self :       Any    )			->			int:






         """simple docstring"""
         return f"""{self.__class__}(\"{self._hand}\")"""

     def __str__(      self :       List[str]    )			->			Optional[int]:






         """simple docstring"""
         return self._hand

     def __eq__(      self :       str						,				A :       Tuple    )			->			List[Any]:






         """simple docstring"""
         if isinstance(A						,				A    ):
             return self.compare_with(A    ) == "Tie"
         return NotImplemented

     def __lt__(      self :       Optional[Any]						,				A :       Tuple    )			->			Optional[int]:






         """simple docstring"""
         if isinstance(A						,				A    ):
             return self.compare_with(A    ) == "Loss"
         return NotImplemented

     def __le__(      self :       Optional[Any]						,				A :       List[Any]    )			->			Union[str, Any]:






         """simple docstring"""
         if isinstance(A						,				A    ):
             return self < other or self == other
         return NotImplemented

     def __gt__(      self :       Dict						,				A :       Dict    )			->			int:






         """simple docstring"""
         if isinstance(A						,				A    ):
             return not self < other and self != other
         return NotImplemented

     def __ge__(      self :       Union[str, Any]						,				A :       int    )			->			int:






         """simple docstring"""
         if isinstance(A						,				A    ):
             return not self < other
         return NotImplemented






     def __hash__(      self :       Union[str, Any]    )			->			str:






         """simple docstring"""
         return object.__hash__(self    )






def        __lowerCAmelCase ():
    # Solution for problem number 54 from Project Euler
    # Input from poker_hands.txt file
    a__      =       0
    a__      =       os.path.abspath(os.path.dirname(UpperCAmelCase_		)		)
    a__      =       os.path.join(UpperCAmelCase_   ,    """poker_hands.txt"""		)
    with open(UpperCAmelCase_		) as file_hand:
        for line in file_hand:
            a__      =       line[:14].strip()
            a__      =       line[15:].strip()
            a__ ,		a__      =       PokerHand(UpperCAmelCase_		), PokerHand(UpperCAmelCase_		)
            a__      =       player.compare_with(UpperCAmelCase_		)
            if output == "Win":
                answer += 1
    return answer


if __name__ == "__main__":
 solution()












import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import SwinaSRImageProcessor
 from transformers.image_transforms import get_image_size







class 		__UpperCAmelCase(		unittest.TestCase ):





     """simple docstring"""



     def __init__(      self :       Optional[int]						,				A :       Dict						,				A :       Union[str, Any]=7						,				A :       List[str]=3						,				A :       Optional[int]=18						,				A :       Optional[int]=30						,				A :       Optional[Any]=4_00						,				A :       Optional[Any]=True						,				A :       Tuple=1 / 2_55						,				A :       Tuple=True						,				A :       Optional[int]=8						,				)			->			Any:






         """simple docstring"""
         a__      =       parent
         a__      =       batch_size
         a__      =       num_channels
         a__      =       image_size
         a__      =       min_resolution
         a__      =       max_resolution
         a__      =       do_rescale
         a__      =       rescale_factor
         a__      =       do_pad
         a__      =       pad_size

     def 				__SCREAMING_SNAKE_CASE		(      self :       List[Any]    )			->			Union[str, Any]:






         """simple docstring"""
         return {
             "do_rescale": self.do_rescale,
             "rescale_factor": self.rescale_factor,
             "do_pad": self.do_pad,
             "pad_size": self.pad_size,
         }






     def 				__SCREAMING_SNAKE_CASE		(      self :       int						,				A :       int=False						,				A :       Any=False						,				A :       List[Any]=False    )			->			Optional[Any]:






         """simple docstring"""
         assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

         if equal_resolution:
             a__      =       []
             for i in range(self.batch_size    ):
                 image_inputs.append(
                     np.random.randint(
                         2_55						,				size=(self.num_channels, self.max_resolution, self.max_resolution)						,				dtype=np.uinta    )    )
         else:
             a__      =       []
             for i in range(self.batch_size    ):
                 a__ ,		a__      =       np.random.choice(np.arange(self.min_resolution						,				self.max_resolution    )						,				2    )
                 image_inputs.append(np.random.randint(2_55						,				size=(self.num_channels, width, height)						,				dtype=np.uinta    )    )

         if not numpify and not torchify:
             # PIL expects the channel dimension as last dimension
             a__      =       [Image.fromarray(np.moveaxis(A						,				0						,				-1    )    ) for x in image_inputs]

         if torchify:
             a__      =       [torch.from_numpy(A    ) for x in image_inputs]

         return image_inputs







@require_torch
@require_vision
class 		__UpperCAmelCase(		lowercase__       ,	unittest.TestCase ):





     """simple docstring"""



     __UpperCAmelCase	: Dict						=    SwinaSRImageProcessor if is_vision_available() else None

     def 				__SCREAMING_SNAKE_CASE		(      self :       int    )			->			Dict:






         """simple docstring"""
         a__      =       SwinaSRImageProcessingTester(self    )

     @property
     def 				__SCREAMING_SNAKE_CASE		(      self :       List[Any]    )			->			List[Any]:






         """simple docstring"""
         return self.image_processor_tester.prepare_image_processor_dict()

     def 				__SCREAMING_SNAKE_CASE		(      self :       Tuple    )			->			int:






         """simple docstring"""
         a__      =       self.image_processing_class(**self.image_processor_dict    )
         self.assertTrue(hasattr(A						,				"""do_rescale"""    )    )
         self.assertTrue(hasattr(A						,				"""rescale_factor"""    )    )
         self.assertTrue(hasattr(A						,				"""do_pad"""    )    )
         self.assertTrue(hasattr(A						,				"""pad_size"""    )    )

     def 				__SCREAMING_SNAKE_CASE		(      self :       Dict    )			->			List[Any]:






         """simple docstring"""
         pass

     def 				__SCREAMING_SNAKE_CASE		(      self :       int						,				A :       Optional[Any]    )			->			List[str]:






         """simple docstring"""
         a__ ,		a__      =       get_image_size(A    )
         a__      =       self.image_processor_tester.pad_size

         a__      =       (old_height // size + 1) * size - old_height
         a__      =       (old_width // size + 1) * size - old_width
         return old_height + pad_height, old_width + pad_width

     def 				__SCREAMING_SNAKE_CASE		(      self :       Any    )			->			Union[str, Any]:






         """simple docstring"""
         # Initialize image_processor
         a__      =       self.image_processing_class(**self.image_processor_dict    )
         # create random PIL images
         a__      =       self.image_processor_tester.prepare_inputs(equal_resolution=A    )
         for image in image_inputs:
             self.assertIsInstance(A						,				Image.Image    )

         # Test not batched input
         a__      =       image_processor(image_inputs[0]						,				return_tensors="""pt"""    ).pixel_values
         a__ ,		a__      =       self.calculate_expected_size(np.array(image_inputs[0]    )    )
         self.assertEqual(
             encoded_images.shape						,				(
                 1,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             )						,				)

     def 				__SCREAMING_SNAKE_CASE		(      self :       Union[str, Any]    )			->			Optional[Any]:






         """simple docstring"""
         # Initialize image_processor
         a__      =       self.image_processing_class(**self.image_processor_dict    )
         # create random numpy tensors
         a__      =       self.image_processor_tester.prepare_inputs(equal_resolution=A						,				numpify=A    )
         for image in image_inputs:
             self.assertIsInstance(A						,				np.ndarray    )

         # Test not batched input
         a__      =       image_processor(image_inputs[0]						,				return_tensors="""pt"""    ).pixel_values
         a__ ,		a__      =       self.calculate_expected_size(image_inputs[0]    )
         self.assertEqual(
             encoded_images.shape						,				(
                 1,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             )						,				)






     def 				__SCREAMING_SNAKE_CASE		(      self :       Union[str, Any]    )			->			Tuple:






         """simple docstring"""
         # Initialize image_processor
         a__      =       self.image_processing_class(**self.image_processor_dict    )
         # create random PyTorch tensors
         a__      =       self.image_processor_tester.prepare_inputs(equal_resolution=A						,				torchify=A    )
         for image in image_inputs:
             self.assertIsInstance(A						,				torch.Tensor    )

         # Test not batched input
         a__      =       image_processor(image_inputs[0]						,				return_tensors="""pt"""    ).pixel_values
         a__ ,		a__      =       self.calculate_expected_size(image_inputs[0]    )
         self.assertEqual(
             encoded_images.shape						,				(
                 1,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             )						,				)






