




"""simple docstring"""

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

import pytest
import requests

_lowerCamelCase	:      Any   =							pathlib.Path.cwd().joinpath('project_euler')
_lowerCamelCase	:      Union[str, Any]   =							pathlib.Path.cwd().joinpath(
    'scripts', 'project_euler_answers.json'
)

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

def 		lowercase_   (		_UpperCAmelCase						):




	"""simple docstring"""






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

def 		lowercase_   (		):




	"""simple docstring"""






	A_	:					List[Any]						 =		[]
	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(_UpperCAmelCase						)
	return solution_file_paths

def 		lowercase_   (		):




	"""simple docstring"""






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

def 		lowercase_   (		):




	"""simple docstring"""






	A_	:					Union[str, Any]						 =		[]
	A_	:					List[Any]						 =		{
	    '''Accept''': '''application/vnd.github.v3+json''',
	    '''Authorization''': '''token ''' + os.environ['''GITHUB_TOKEN'''],
	}
	A_	:					Optional[int]						 =		requests.get(get_files_url()	,   headers=_UpperCAmelCase						).json()
	for file in files:
		A_	:					List[str]						 =		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(_UpperCAmelCase						)
	return solution_file_paths

def 		lowercase_   (		):




	"""simple docstring"""






	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 _UpperCAmelCase						: f"""{path.parent.name}/{path.name}"""	,   )
def 		lowercase_   (		_UpperCAmelCase						):




	"""simple docstring"""






	A_	:					str						 =		solution_path.parent.name[8:].zfill(3						)
	A_	:					str						 =		PROBLEM_ANSWERS[problem_number]
	A_	:					str						 =		convert_path_to_module(_UpperCAmelCase						)
	A_	:					Tuple						 =		str(solution_module.solution()						)  # type: ignore
	A_	:					Dict						 =		hashlib.shaaaa(answer.encode()						).hexdigest()
	assert (
	    answer == expected
	), f"""Expected solution to {problem_number} to have hash {expected}, got {answer}"""











"""simple docstring"""

from __future__ import annotations

def 		lowercase_   (		_UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase						):




	"""simple docstring"""






	assert (
	    c % greatest_common_divisor(_UpperCAmelCase	,   _UpperCAmelCase						) == 0
	)  # greatest_common_divisor(a,b) function implemented below
	((A_) ,			(A_) ,			(A_))	:					List[Any]						 =		extended_gcd(_UpperCAmelCase	,   _UpperCAmelCase						)  # extended_gcd(a,b) function implemented below
	A_	:					int						 =		c / d
	return (r * x, r * y)

def 		lowercase_   (		_UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase = 2						):




	"""simple docstring"""






	((A_) ,			(A_))	:					Any						 =		diophantine(_UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase						)  # Initial value
	A_	:					Union[str, Any]						 =		greatest_common_divisor(_UpperCAmelCase	,   _UpperCAmelCase						)
	A_	:					List[str]						 =		a // d
	A_	:					str						 =		b // d

	for i in range(_UpperCAmelCase						):
		A_	:					int						 =		xa + i * q
		A_	:					str						 =		ya - i * p
		print(_UpperCAmelCase	,   _UpperCAmelCase						)

def 		lowercase_   (		_UpperCAmelCase	,   _UpperCAmelCase						):




	"""simple docstring"""






	if a < b:
		A_ ,			A_	:					Tuple						 =		b, a

	while a % b != 0:
		A_ ,			A_	:					int						 =		b, a % b

	return b

def 		lowercase_   (		_UpperCAmelCase	,   _UpperCAmelCase						):




	"""simple docstring"""






	assert a >= 0 and b >= 0

	if b == 0:
		A_ ,			A_ ,			A_	:					str						 =		a, 1, 0
	else:
		((A_) ,			(A_) ,			(A_))	:					List[str]						 =		extended_gcd(_UpperCAmelCase	,   a % b						)
		A_	:					Optional[int]						 =		q
		A_	:					Tuple						 =		p - q * (a // b)

	assert a % d == 0 and b % d == 0
	assert d == a * x + b * y

	return (d, x, y)


if __name__ == "__main__":
		from doctest import testmod

		testmod(name='diophantine', verbose=True)
		testmod(name='diophantine_all_soln', verbose=True)
		testmod(name='extended_gcd', verbose=True)
		testmod(name='greatest_common_divisor', verbose=True)





