From 6fc67e8a0aeb3d3e922fa4faf9288ce885f706a2 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 4 Nov 2021 16:13:05 +0000 Subject: [PATCH 1/3] updating DIRECTORY.md --- DIRECTORY.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index fd164c92e11c..32ca8cd3b256 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -253,6 +253,7 @@ ## Dynamic Programming * [Abbreviation](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/abbreviation.py) + * [All Construct](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/all_construct.py) * [Bitmask](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/bitmask.py) * [Catalan Numbers](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/catalan_numbers.py) * [Climbing Stairs](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/climbing_stairs.py) @@ -612,6 +613,7 @@ ## Physics * [N Body Simulation](https://github.com/TheAlgorithms/Python/blob/master/physics/n_body_simulation.py) + * [Newtons Second Law Of Motion](https://github.com/TheAlgorithms/Python/blob/master/physics/newtons_second_law_of_motion.py) ## Project Euler * Problem 001 @@ -1018,6 +1020,7 @@ * [Nasa Data](https://github.com/TheAlgorithms/Python/blob/master/web_programming/nasa_data.py) * [Random Anime Character](https://github.com/TheAlgorithms/Python/blob/master/web_programming/random_anime_character.py) * [Recaptcha Verification](https://github.com/TheAlgorithms/Python/blob/master/web_programming/recaptcha_verification.py) + * [Reddit](https://github.com/TheAlgorithms/Python/blob/master/web_programming/reddit.py) * [Search Books By Isbn](https://github.com/TheAlgorithms/Python/blob/master/web_programming/search_books_by_isbn.py) * [Slack Message](https://github.com/TheAlgorithms/Python/blob/master/web_programming/slack_message.py) * [Test Fetch Github Info](https://github.com/TheAlgorithms/Python/blob/master/web_programming/test_fetch_github_info.py) From d796de4fb2258382ced8a9e35c97dec060f25078 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Fri, 5 Nov 2021 03:44:58 +0300 Subject: [PATCH 2/3] Fix typo --- project_euler/problem_043/sol1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_euler/problem_043/sol1.py b/project_euler/problem_043/sol1.py index 1febe4a4d37f..a99cc9ba6b7d 100644 --- a/project_euler/problem_043/sol1.py +++ b/project_euler/problem_043/sol1.py @@ -43,7 +43,7 @@ def is_substring_divisible(num: tuple) -> bool: def solution(n: int = 10) -> int: """ Returns the sum of all pandigital numbers which pass the - divisiility tests. + divisibility tests. >>> solution(10) 16695334890 """ From 430013698ca3f80320970465e19c477a84358408 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Fri, 5 Nov 2021 12:30:34 +0300 Subject: [PATCH 3/3] Improve solution --- project_euler/problem_043/sol1.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/project_euler/problem_043/sol1.py b/project_euler/problem_043/sol1.py index a99cc9ba6b7d..c533f40da9c9 100644 --- a/project_euler/problem_043/sol1.py +++ b/project_euler/problem_043/sol1.py @@ -33,9 +33,18 @@ def is_substring_divisible(num: tuple) -> bool: >>> is_substring_divisible((1, 4, 0, 6, 3, 5, 7, 2, 8, 9)) True """ - tests = [2, 3, 5, 7, 11, 13, 17] + if num[3] % 2 != 0: + return False + + if (num[2] + num[3] + num[4]) % 3 != 0: + return False + + if num[5] % 5 != 0: + return False + + tests = [7, 11, 13, 17] for i, test in enumerate(tests): - if (num[i + 1] * 100 + num[i + 2] * 10 + num[i + 3]) % test != 0: + if (num[i + 4] * 100 + num[i + 5] * 10 + num[i + 6]) % test != 0: return False return True @@ -47,13 +56,11 @@ def solution(n: int = 10) -> int: >>> solution(10) 16695334890 """ - list_nums = [ + return sum( int("".join(map(str, num))) for num in permutations(range(n)) if is_substring_divisible(num) - ] - - return sum(list_nums) + ) if __name__ == "__main__":