add solution to Project Euler problem 206

This commit is contained in:
nico 2020-10-13 00:21:04 +02:00
parent 50d7ed8417
commit 53568cf4ef
2 changed files with 30 additions and 0 deletions

View File

View 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())