File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
project_euler/problem_206 Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
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 ())
You can’t perform that action at this time.
0 commit comments