
import math


class   __lowerCAmelCase		:



      """simple docstring"""







      def __init__( self						:    Tuple			,    _snake_case						:    int			,    _snake_case						:    int			,    _snake_case						:    int			,    _snake_case						:    Union[str, Any]			):
          __lowercase						:     Union[str, Any]		      =    x
          __lowercase						:     int		      =    y
          __lowercase						:     Tuple		      =    step_size
          __lowercase						:     List[str]		      =    function_to_optimize




      def 						snake_case_     ( self						:    Tuple			):
          return self.function(self.x			,    self.y			)




      def 						snake_case_     ( self						:    Dict			):
          __lowercase						:     List[str]		      =    self.step_size
          return [
              SearchProblem(_snake_case			,    _snake_case			,    _snake_case			,    self.function			)
              for x, y in (
                  (self.x - step_size, self.y - step_size),
                  (self.x - step_size, self.y),
                  (self.x - step_size, self.y + step_size),
                  (self.x, self.y - step_size),
                  (self.x, self.y + step_size),
                  (self.x + step_size, self.y - step_size),
                  (self.x + step_size, self.y),
                  (self.x + step_size, self.y + step_size),
              )
          ]




      def __hash__( self						:    int			):
          return hash(str(self			)			)




      def __eq__( self						:    Optional[Any]			,    _snake_case						:    str			):
          if isinstance(_snake_case			,    _snake_case			):
              return hash(str(self			)			) == hash(str(_snake_case			)			)
          return False




      def __str__( self						:    Dict			):
          return F'x: {self.x} y: {self.y}'






def       UpperCAmelCase_					(  __lowerCAmelCase		,   __lowerCAmelCase = True		,   __lowerCAmelCase = math.inf		,   __lowerCAmelCase = -math.inf		,   __lowerCAmelCase = math.inf		,   __lowerCAmelCase = -math.inf		,   __lowerCAmelCase = False		,   __lowerCAmelCase = 10_000		,   )	->  SearchProblem:
    __lowercase						:     str		      =    search_prob
    __lowercase						:     Optional[Any]		      =    []  # list to store the current score at each iteration
    __lowercase						:     Optional[Any]		      =    0
    __lowercase						:     Any		      =    False
    __lowercase						:     str		      =    set()
    while not solution_found and iterations < max_iter:
        visited.add(__lowerCAmelCase		)
        iterations += 1
        __lowercase						:     Union[str, Any]		      =    current_state.score()
        scores.append(__lowerCAmelCase		)
        __lowercase						:     Tuple		      =    current_state.get_neighbors()
        __lowercase						:     List[Any]		      =    -math.inf
        __lowercase						:     int		      =    math.inf
        __lowercase						:     List[Any]		      =    None  # to hold the next best neighbor
        for neighbor in neighbors:
            if neighbor in visited:
                continue  # do not want to visit the same state again
            if (
                neighbor.x > max_x
                or neighbor.x < min_x
                or neighbor.y > max_y
                or neighbor.y < min_y
            ):
                continue  # neighbor outside our bounds
            __lowercase						:     Union[str, Any]		      =    neighbor.score() - current_score
            if find_max:  # finding max
                # going to direction with greatest ascent
                if change > max_change and change > 0:
                    __lowercase						:     List[Any]		      =    change
                    __lowercase						:     Any		      =    neighbor
            else:  # finding min
                # to direction with greatest descent
                if change < min_change and change < 0:
                    __lowercase						:     Optional[int]		      =    change
                    __lowercase						:     int		      =    neighbor
        if next_state is not None:
            # we found at least one neighbor which improved the current state
            __lowercase						:     Any		      =    next_state
        else:
            # since we have no neighbor that improves the solution we stop the search
            __lowercase						:     str		      =    True

    if visualization:
        from matplotlib import pyplot as plt

        plt.plot(range(__lowerCAmelCase		)		,   __lowerCAmelCase		)
        plt.xlabel('''Iterations'''		)
        plt.ylabel('''Function values'''		)
        plt.show()

    return current_state


if __name__ == "__main__":
 import doctest

 doctest.testmod()


 def       UpperCAmelCase_					(  __lowerCAmelCase		,   __lowerCAmelCase		)	->  int:
     return (x**2) + (y**2)

 # starting the problem with initial coordinates (3, 4)
 __lowerCAmelCase   :     str      =						SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_fa)
 __lowerCAmelCase   :     List[Any]      =						hill_climbing(prob, find_max=False)
 print(
     "The minimum score for f(x, y) = x^2 + y^2 found via hill climbing: "
     F'{local_min.score()}'
 )

 # starting the problem with initial coordinates (12, 47)
 __lowerCAmelCase   :     List[str]      =						SearchProblem(x=12, y=47, step_size=1, function_to_optimize=test_fa)
 __lowerCAmelCase   :     int      =						hill_climbing(
     prob, find_max=False, max_x=100, min_x=5, max_y=50, min_y=-5, visualization=True
 )
 print(
     "The minimum score for f(x, y) = x^2 + y^2 with the domain 100 > x > 5 "
     F'and 50 > y > - 5 found via hill climbing: {local_min.score()}'
 )


 def       UpperCAmelCase_					(  __lowerCAmelCase		,   __lowerCAmelCase		)	->  Union[str, Any]:
     return (3 * x**2) - (6 * y)

 __lowerCAmelCase   :     List[Any]      =						SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_fa)
 __lowerCAmelCase   :     Optional[Any]      =						hill_climbing(prob, find_max=True)





 print(
     "The maximum score for f(x, y) = x^2 + y^2 found via hill climbing: "
     F'{local_min.score()}'
 )




from __future__ import annotations

from collections import Counter


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  list[int]:
    __lowercase						:     Any		      =    [True] * n
    __lowercase						:     str		      =    False
    __lowercase						:     int		      =    False
    __lowercase						:     List[Any]		      =    True

    for i in range(3		,   int(n**0.5 + 1		)		,   2		):
        __lowercase						:     List[str]		      =    i * 2
        while index < n:
            __lowercase						:     List[Any]		      =    False
            __lowercase						:     Dict		      =    index + i

    __lowercase						:     Tuple		      =    [2]

    for i in range(3		,   __lowerCAmelCase		,   2		):
        if is_prime[i]:
            primes.append(__lowerCAmelCase		)

    return primes


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  list[list[int]]:
    __lowercase						:     Optional[int]		      =    str(__lowerCAmelCase		)
    __lowercase						:     List[str]		      =    []
    __lowercase						:     int		      =    ['''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''']

    for duplicate in Counter(__lowerCAmelCase		) - Counter(set(__lowerCAmelCase		)		):
        __lowercase						:     Union[str, Any]		      =    [int(number_str.replace(__lowerCAmelCase		,   __lowerCAmelCase		)		) for digit in digits]
        replacements.append(__lowerCAmelCase		)

    return replacements


def       UpperCAmelCase_					(  __lowerCAmelCase = 8		)	->  int:
    __lowercase						:     Tuple		      =    set()

    # Filter primes with less than 3 replaceable digits
    __lowercase						:     int		      =    {
        x for x in set(prime_sieve(1_000_000		)		) if len(str(__lowerCAmelCase		)		) - len(set(str(__lowerCAmelCase		)		)		) >= 3
    }

    for prime in primes:
        if prime in numbers_checked:
            continue

        __lowercase						:     str		      =    digit_replacements(__lowerCAmelCase		)

        for family in replacements:
            numbers_checked.update(__lowerCAmelCase		)
            __lowercase						:     List[Any]		      =    primes.intersection(__lowerCAmelCase		)

            if len(__lowerCAmelCase		) != family_length:
                continue

            return min(__lowerCAmelCase		)

    return -1


if __name__ == "__main__":
 print(solution())


