

"""simple docstring"""





import hashlib
import importlib.util
import json
import os
import pathlib
from types import ModuleType

import pytest
import requests

__UpperCamelCase						:   int							   =	pathlib.Path.cwd().joinpath('''project_euler''')
__UpperCamelCase						:   Tuple							   =	pathlib.Path.cwd().joinpath(
    '''scripts''', '''project_euler_answers.json'''
)

with open(PROJECT_EULER_ANSWERS_PATH) as file_handle:
							__UpperCamelCase						:   dict[str, str]							   =	json.load(file_handle)

def 						__SCREAMING_SNAKE_CASE						(   A_				):
	lowerCAmelCase__			:		List[Any]						       =			importlib.util.spec_from_file_location(file_path.name		,  str(A_				)				)
	lowerCAmelCase__			:		Any						       =			importlib.util.module_from_spec(A_				)  # type: ignore
	spec.loader.exec_module(A_				)  # type: ignore
	return module

def 						__SCREAMING_SNAKE_CASE						(   ):
	lowerCAmelCase__			:		Dict						       =			[]
	for problem_dir_path in PROJECT_EULER_DIR_PATH.iterdir():
		if problem_dir_path.is_file() or problem_dir_path.name.startswith('''_'''				):
			continue
		for file_path in problem_dir_path.iterdir():
			if file_path.suffix != ".py" or file_path.name.startswith(('''_''', '''test''')				):
				continue
			solution_file_paths.append(A_				)
	return solution_file_paths

def 						__SCREAMING_SNAKE_CASE						(   ):
	with open(os.environ['''GITHUB_EVENT_PATH''']				) as file:
		lowerCAmelCase__			:		List[str]						       =			json.load(A_				)
	return event["pull_request"]["url"] + "/files"

def 						__SCREAMING_SNAKE_CASE						(   ):
	lowerCAmelCase__			:		Optional[int]						       =			[]
	lowerCAmelCase__			:		List[Any]						       =			{
	    '''Accept''': '''application/vnd.github.v3+json''',
	    '''Authorization''': '''token ''' + os.environ['''GITHUB_TOKEN'''],
	}
	lowerCAmelCase__			:		Optional[Any]						       =			requests.get(get_files_url()		,  headers=A_				).json()
	for file in files:
		lowerCAmelCase__			:		Optional[Any]						       =			pathlib.Path.cwd().joinpath(file['''filename''']				)
		if (
		    filepath.suffix != ".py"
		    or filepath.name.startswith(('''_''', '''test''')				)
		    or not filepath.name.startswith('''sol'''				)
		):
			continue
		solution_file_paths.append(A_				)
	return solution_file_paths

def 						__SCREAMING_SNAKE_CASE						(   ):
	if os.environ.get('''CI'''				) and os.environ.get('''GITHUB_EVENT_NAME'''				) == "pull_request":
		# Return only if there are any, otherwise default to all solutions
		if filepaths := added_solution_file_path():
			return filepaths
	return all_solution_file_paths()





@pytest.mark.parametrize(
    '''solution_path'''		,  collect_solution_file_paths()		,  ids=lambda A_				: f'{path.parent.name}/{path.name}'		,  )
def 						__SCREAMING_SNAKE_CASE						(   A_				):
	lowerCAmelCase__			:		str						       =			solution_path.parent.name[8:].zfill(3				)
	lowerCAmelCase__			:		str						       =			PROBLEM_ANSWERS[problem_number]
	lowerCAmelCase__			:		Optional[Any]						       =			convert_path_to_module(A_				)
	lowerCAmelCase__			:		Union[str, Any]						       =			str(solution_module.solution()				)  # type: ignore
	lowerCAmelCase__			:		int						       =			hashlib.shaaaa(answer.encode()				).hexdigest()
	assert (
	    answer == expected
	), f'Expected solution to {problem_number} to have hash {expected}, got {answer}'







"""simple docstring"""





from itertools import permutations

def 						__SCREAMING_SNAKE_CASE						(   A_ = 5				):
	if gon_side < 3 or gon_side > 5:
		raise ValueError('''gon_side must be in the range [3, 5]'''				)

	# Since it's 16, we know 10 is on the outer ring
	# Put the big numbers at the end so that they are never the first number
	lowerCAmelCase__			:		str						       =			list(range(gon_side + 1		,  0		,  -1				)				)
	lowerCAmelCase__			:		int						       =			list(range(gon_side + 2		,  gon_side * 2 + 1				)				)

	for perm in permutations(small_numbers + big_numbers				):
		lowerCAmelCase__			:		Optional[Any]						       =			generate_gon_ring(A_		,  list(A_				)				)
		if is_magic_gon(A_				):
			return int(''''''.join(str(A_				) for n in numbers				)				)

	lowerCAmelCase__			:		Tuple						       =			f'Magic {gon_side}-gon ring is impossible'
	raise ValueError(A_				)

def 						__SCREAMING_SNAKE_CASE						(   A_		,  A_				):
	lowerCAmelCase__			:		Dict						       =			[0] * (gon_side * 3)
	lowerCAmelCase__			:		Optional[int]						       =			perm[0:3]
	perm.append(perm[1]				)

	lowerCAmelCase__			:		int						       =			1 if gon_side < 5 else 2

	for i in range(1		,  len(A_				) // 3 + magic_number				):
		lowerCAmelCase__			:		List[str]						       =			perm[2 * i + 1]
		lowerCAmelCase__			:		Optional[int]						       =			result[3 * i - 1]
		lowerCAmelCase__			:		List[Any]						       =			perm[2 * i + 2]

	return result

def 						__SCREAMING_SNAKE_CASE						(   A_				):
	if len(A_				) % 3 != 0:
		raise ValueError('''a gon ring should have a length that is a multiple of 3'''				)

	if min(numbers[::3]				) != numbers[0]:
		return False

	lowerCAmelCase__			:		int						       =			sum(numbers[:3]				)

	return all(sum(numbers[i : i + 3]				) == total for i in range(3		,  len(A_				)		,  3				)				)


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




