From 53568cf4efd84f4b1c039eade335655842fa29e3 Mon Sep 17 00:00:00 2001 From: nico Date: Tue, 13 Oct 2020 00:21:04 +0200 Subject: [PATCH] add solution to Project Euler problem 206 --- project_euler/problem_206/__init__.py | 0 project_euler/problem_206/sol1.py | 30 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 project_euler/problem_206/__init__.py create mode 100644 project_euler/problem_206/sol1.py diff --git a/project_euler/problem_206/__init__.py b/project_euler/problem_206/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/project_euler/problem_206/sol1.py b/project_euler/problem_206/sol1.py new file mode 100644 index 000000000..b2de1e499 --- /dev/null +++ b/project_euler/problem_206/sol1.py @@ -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())