


import math


class        __lowerCamelCase      :


				"""simple docstring"""







				def __init__(				self     :    str	,							lowerCamelCase_     :    int	,							lowerCamelCase_     :    int	,							lowerCamelCase_     :    int	,							lowerCamelCase_     :    int					):
								_lowerCAmelCase  						=x
								_lowerCAmelCase  						=y
								_lowerCAmelCase  						=step_size
								_lowerCAmelCase  						=function_to_optimize






				def        lowerCAmelCase__			(				self     :    Optional[Any]					):
								return self.function(self.x	,							self.y					)






				def        lowerCAmelCase__			(				self     :    List[str]					):
								_lowerCAmelCase  						=self.step_size
								return [
								    SearchProblem(lowerCamelCase_	,							lowerCamelCase_	,							lowerCamelCase_	,							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     :    Any	,							lowerCamelCase_     :    Any					):
								if isinstance(lowerCamelCase_	,							lowerCamelCase_					):
												return hash(str(self					)					) == hash(str(lowerCamelCase_					)					)
								return False






				def __str__(				self     :    List[Any]					):
								return F"x: {self.x} y: {self.y}"

def 		snake_case_   (				lowercase__     :    Any       ,     lowercase__     :    bool = True       ,     lowercase__     :    float = math.inf       ,     lowercase__     :    float = -math.inf       ,     lowercase__     :    float = math.inf       ,     lowercase__     :    float = -math.inf       ,     lowercase__     :    bool = False       ,     lowercase__     :    int = 1_00_00       ,     ):






				'''simple docstring'''






				_lowerCAmelCase  						=search_prob
				_lowerCAmelCase  						=[]  # list to store the current score at each iteration
				_lowerCAmelCase  						=0
				_lowerCAmelCase  						=False
				_lowerCAmelCase  						=set()
				while not solution_found and iterations < max_iter:
								visited.add(lowercase__     )
								iterations += 1
								_lowerCAmelCase  						=current_state.score()
								scores.append(lowercase__     )
								_lowerCAmelCase  						=current_state.get_neighbors()
								_lowerCAmelCase  						=-math.inf
								_lowerCAmelCase  						=math.inf
								_lowerCAmelCase  						=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
												_lowerCAmelCase  						=neighbor.score() - current_score
												if find_max:  # finding max
																# going to direction with greatest ascent
																if change > max_change and change > 0:
																				_lowerCAmelCase  						=change
																				_lowerCAmelCase  						=neighbor
												else:  # finding min
																# to direction with greatest descent
																if change < min_change and change < 0:
																				_lowerCAmelCase  						=change
																				_lowerCAmelCase  						=neighbor
								if next_state is not None:
												# we found at least one neighbor which improved the current state
												_lowerCAmelCase  						=next_state
								else:
												# since we have no neighbor that improves the solution we stop the search
												_lowerCAmelCase  						=True

				if visualization:
								from matplotlib import pyplot as plt

								plt.plot(range(lowercase__     )       ,     lowercase__     )
								plt.xlabel("""Iterations"""     )
								plt.ylabel("""Function values"""     )
								plt.show()

				return current_state


if __name__ == "__main__":
		import doctest

		doctest.testmod()

		def 		snake_case_   (				lowercase__     :    List[str]       ,     lowercase__     :    str     ):






						'''simple docstring'''






						return (x**2) + (y**2)

		# starting the problem with initial coordinates (3, 4)
		__SCREAMING_SNAKE_CASE	:							Optional[Any]           =  SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_fa)
		__SCREAMING_SNAKE_CASE	:							int           =  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)
		__SCREAMING_SNAKE_CASE	:							List[Any]           =  SearchProblem(x=12, y=47, step_size=1, function_to_optimize=test_fa)
		__SCREAMING_SNAKE_CASE	:							List[Any]           =  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 		snake_case_   (				lowercase__     :    List[Any]       ,     lowercase__     :    List[str]     ):






						'''simple docstring'''






						return (3 * x**2) - (6 * y)

		__SCREAMING_SNAKE_CASE	:							Union[str, Any]           =  SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_fa)
		__SCREAMING_SNAKE_CASE	:							Tuple           =  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

import math
from itertools import permutations

def 		snake_case_   (				lowercase__     :    int     ):






				'''simple docstring'''






				if 1 < number < 4:
								# 2 and 3 are primes
								return True
				elif number < 2 or number % 2 == 0 or number % 3 == 0:
								# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
								return False

				# All primes number are in format of 6k +/- 1
				for i in range(5       ,     int(math.sqrt(lowercase__     ) + 1     )       ,     6     ):
								if number % i == 0 or number % (i + 2) == 0:
												return False
				return True

def 		snake_case_   (				lowercase__     :    int = 7     ):






				'''simple docstring'''






				_lowerCAmelCase  						="""""".join(str(lowercase__     ) for i in range(1       ,     n + 1     )     )
				_lowerCAmelCase  						=[int("""""".join(lowercase__     )     ) for i in permutations(lowercase__       ,     lowercase__     )]
				_lowerCAmelCase  						=[num for num in perm_list if is_prime(lowercase__     )]
				return max(lowercase__     ) if pandigitals else 0


if __name__ == "__main__":
		print(F'{solution() = }')

