From 1d0f5ee365361cbfcad3383278fa5974fe31a3ac Mon Sep 17 00:00:00 2001 From: Gonzalo Gamez Date: Fri, 23 Oct 2020 22:17:30 -0500 Subject: [PATCH 1/5] redoing adding 206 pr --- DIRECTORY.md | 2 ++ project_euler/problem_206/__init__.py | 0 project_euler/problem_206/sol1.py | 52 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 project_euler/problem_206/__init__.py create mode 100644 project_euler/problem_206/sol1.py diff --git a/DIRECTORY.md b/DIRECTORY.md index f0f494e7a3b4..74af068fc268 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -712,6 +712,8 @@ * [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_174/sol1.py) * Problem 191 * [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_191/sol1.py) + * Problem 206 + * [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_206/sol1.py) * Problem 234 * [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_234/sol1.py) * Problem 551 diff --git a/project_euler/problem_206/__init__.py b/project_euler/problem_206/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/project_euler/problem_206/sol1.py b/project_euler/problem_206/sol1.py new file mode 100644 index 000000000000..5190d5b36938 --- /dev/null +++ b/project_euler/problem_206/sol1.py @@ -0,0 +1,52 @@ +""" +Problem 206 : https://projecteuler.net/problem=206 + +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. + +Solution: Finding a square number can found by adding consecutive odd numbers +starting from 1. The minimum number possible for perfect square is 1020304050607080900 +in this situation, so started checking digits are in correct places after +total is above it. + +""" + +import math + +def solution() -> int: + """ + >>> solution() + 1389019170 + """ + + + total = 1 + add = 1 + + while True: + + #adding odds + add += 2 + total += add + + #starts count here since the bottom limit + if total > 1020304050607080900: + + #nested if statements to check digits + num = str(total) + if int(num[-1]) == 0: + if int(num[-3]) == 9: + if int(num[-5]) == 8: + if int(num[-7]) == 7: + if int(num[-9]) == 6: + if int(num[-11]) == 5: + if int(num[-13]) == 4: + if int(num[-15]) == 3: + if int(num[-17]) == 2: + if int(num[-19]) == 1: + break + + return int(math.sqrt(total)) + +if __name__ == "__main__": + print(f"{solution() = }") From e54acff20115fcdd8bb9c7e6717831656ed04f5c Mon Sep 17 00:00:00 2001 From: Gonzalo Gamez Date: Fri, 23 Oct 2020 22:38:50 -0500 Subject: [PATCH 2/5] trim trailing whitespace --- project_euler/problem_206/sol1.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/project_euler/problem_206/sol1.py b/project_euler/problem_206/sol1.py index 5190d5b36938..72e1207976dc 100644 --- a/project_euler/problem_206/sol1.py +++ b/project_euler/problem_206/sol1.py @@ -4,14 +4,14 @@ 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. -Solution: Finding a square number can found by adding consecutive odd numbers +Solution: Finding a square number can found by adding consecutive odd numbers starting from 1. The minimum number possible for perfect square is 1020304050607080900 -in this situation, so started checking digits are in correct places after -total is above it. +in this situation, so started checking digits are in correct places after +total is above it. """ -import math +import math def solution() -> int: """ @@ -32,7 +32,7 @@ def solution() -> int: #starts count here since the bottom limit if total > 1020304050607080900: - #nested if statements to check digits + #nested if statements to check digits num = str(total) if int(num[-1]) == 0: if int(num[-3]) == 9: @@ -47,6 +47,6 @@ def solution() -> int: break return int(math.sqrt(total)) - + if __name__ == "__main__": print(f"{solution() = }") From ce92f8866c89777cadecbc304cbe5d6c771846a9 Mon Sep 17 00:00:00 2001 From: Gonzalo Gamez Date: Fri, 23 Oct 2020 22:41:47 -0500 Subject: [PATCH 3/5] more comments --- project_euler/problem_206/sol1.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/project_euler/problem_206/sol1.py b/project_euler/problem_206/sol1.py index 72e1207976dc..5c022a6f8293 100644 --- a/project_euler/problem_206/sol1.py +++ b/project_euler/problem_206/sol1.py @@ -8,7 +8,6 @@ starting from 1. The minimum number possible for perfect square is 1020304050607080900 in this situation, so started checking digits are in correct places after total is above it. - """ import math @@ -19,7 +18,7 @@ def solution() -> int: 1389019170 """ - + #adding odds total = 1 add = 1 From 7a39da3205795483a693cad1d33a42f4b62c30a6 Mon Sep 17 00:00:00 2001 From: Gonzalo Gamez Date: Fri, 23 Oct 2020 22:57:36 -0500 Subject: [PATCH 4/5] format with black --- project_euler/problem_206/sol1.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/project_euler/problem_206/sol1.py b/project_euler/problem_206/sol1.py index 5c022a6f8293..d01e9e78d96a 100644 --- a/project_euler/problem_206/sol1.py +++ b/project_euler/problem_206/sol1.py @@ -12,26 +12,27 @@ import math + def solution() -> int: """ >>> solution() 1389019170 """ - #adding odds + # adding odds total = 1 add = 1 while True: - #adding odds + # adding odds add += 2 total += add - #starts count here since the bottom limit + # starts count here since the bottom limit if total > 1020304050607080900: - #nested if statements to check digits + # nested if statements to check digits num = str(total) if int(num[-1]) == 0: if int(num[-3]) == 9: @@ -47,5 +48,6 @@ def solution() -> int: return int(math.sqrt(total)) + if __name__ == "__main__": print(f"{solution() = }") From 4b42a93aa9d569862e783d9026e6ba268934e310 Mon Sep 17 00:00:00 2001 From: Gonzalo Gamez <32805901+Takosaga@users.noreply.github.com> Date: Sat, 24 Oct 2020 03:07:08 -0500 Subject: [PATCH 5/5] Update project_euler/problem_206/sol1.py Co-authored-by: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com>