mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-30 22:23:42 +00:00
add solution to Project Euler problem 206
This commit is contained in:
parent
50d7ed8417
commit
53568cf4ef
0
project_euler/problem_206/__init__.py
Normal file
0
project_euler/problem_206/__init__.py
Normal file
30
project_euler/problem_206/sol1.py
Normal file
30
project_euler/problem_206/sol1.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
"""
|
||||
Problem Statement:
|
||||
Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,
|
||||
where each “_” is a single digit.
|
||||
"""
|
||||
|
||||
from itertools import product
|
||||
|
||||
|
||||
def solution() -> int:
|
||||
"""
|
||||
Returns the positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0 using
|
||||
itertool product to generate all possible digit combinations 0...9 for the nine "_"
|
||||
to fill.
|
||||
|
||||
>>> solution()
|
||||
1389019170
|
||||
"""
|
||||
|
||||
for p in product("0123456789"[::-1], repeat=9):
|
||||
squared = int("1{}2{}3{}4{}5{}6{}7{}8{}9{}0".format(*p))
|
||||
|
||||
root_integer = int(squared ** 0.5)
|
||||
|
||||
if root_integer ** 2 == squared:
|
||||
return root_integer
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(solution())
|
Loading…
Reference in New Issue
Block a user