Skip to content

Commit 53568cf

Browse files
author
nico
committed
add solution to Project Euler problem 206
1 parent 50d7ed8 commit 53568cf

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Diff for: project_euler/problem_206/__init__.py

Whitespace-only changes.

Diff for: project_euler/problem_206/sol1.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Problem Statement:
3+
Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,
4+
where each “_” is a single digit.
5+
"""
6+
7+
from itertools import product
8+
9+
10+
def solution() -> int:
11+
"""
12+
Returns the positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0 using
13+
itertool product to generate all possible digit combinations 0...9 for the nine "_"
14+
to fill.
15+
16+
>>> solution()
17+
1389019170
18+
"""
19+
20+
for p in product("0123456789"[::-1], repeat=9):
21+
squared = int("1{}2{}3{}4{}5{}6{}7{}8{}9{}0".format(*p))
22+
23+
root_integer = int(squared ** 0.5)
24+
25+
if root_integer ** 2 == squared:
26+
return root_integer
27+
28+
29+
if __name__ == "__main__":
30+
print(solution())

0 commit comments

Comments
 (0)