From 6b60eaacc3e381524f128e016c3a35c14670b2ff Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 10 Mar 2023 20:07:21 +0000 Subject: [PATCH 1/7] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index f25b0c6ff4e3..b2daaaa9c47d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -334,6 +334,7 @@ ## Electronics * [Builtin Voltage](electronics/builtin_voltage.py) * [Carrier Concentration](electronics/carrier_concentration.py) + * [Circular Convolution](electronics/circular_convolution.py) * [Coulombs Law](electronics/coulombs_law.py) * [Electric Conductivity](electronics/electric_conductivity.py) * [Electric Power](electronics/electric_power.py) From 581ca58884785cf1dc1a900d9e943e04be6e56b5 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 14 Mar 2023 07:03:39 +0000 Subject: [PATCH 2/7] updating DIRECTORY.md --- DIRECTORY.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index e1ce44eedce1..e932a1e0522a 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -196,11 +196,14 @@ * [Disjoint Set](data_structures/disjoint_set/disjoint_set.py) * Hashing * [Double Hash](data_structures/hashing/double_hash.py) + * [Hash Map](data_structures/hashing/hash_map.py) * [Hash Table](data_structures/hashing/hash_table.py) * [Hash Table With Linked List](data_structures/hashing/hash_table_with_linked_list.py) * Number Theory * [Prime Numbers](data_structures/hashing/number_theory/prime_numbers.py) * [Quadratic Probing](data_structures/hashing/quadratic_probing.py) + * Tests + * [Test Hash Map](data_structures/hashing/tests/test_hash_map.py) * Heap * [Binomial Heap](data_structures/heap/binomial_heap.py) * [Heap](data_structures/heap/heap.py) From 7c5f091ae31a953867789735659748936845730b Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 1 Apr 2023 11:01:36 +0000 Subject: [PATCH 3/7] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 1a641d8ecb59..33c816fc4add 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -317,6 +317,7 @@ * [Longest Sub Array](dynamic_programming/longest_sub_array.py) * [Matrix Chain Order](dynamic_programming/matrix_chain_order.py) * [Max Non Adjacent Sum](dynamic_programming/max_non_adjacent_sum.py) + * [Max Product Subarray](dynamic_programming/max_product_subarray.py) * [Max Sub Array](dynamic_programming/max_sub_array.py) * [Max Sum Contiguous Subsequence](dynamic_programming/max_sum_contiguous_subsequence.py) * [Min Distance Up Bottom](dynamic_programming/min_distance_up_bottom.py) From fcc3bc4753e2af90a168a47b71976ab087f9d035 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sat, 1 Apr 2023 14:31:01 +0300 Subject: [PATCH 4/7] Add solution --- project_euler/problem_094/__init__.py | 0 project_euler/problem_094/sol1.py | 44 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 project_euler/problem_094/__init__.py create mode 100644 project_euler/problem_094/sol1.py diff --git a/project_euler/problem_094/__init__.py b/project_euler/problem_094/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/project_euler/problem_094/sol1.py b/project_euler/problem_094/sol1.py new file mode 100644 index 000000000000..c26df6f1848b --- /dev/null +++ b/project_euler/problem_094/sol1.py @@ -0,0 +1,44 @@ +""" +Project Euler Problem 94: https://projecteuler.net/problem=94 + +It is easily proved that no equilateral triangle exists with integral length sides and +integral area. However, the almost equilateral triangle 5-5-6 has an area of 12 square +units. + +We shall define an almost equilateral triangle to be a triangle for which two sides are +equal and the third differs by no more than one unit. + +Find the sum of the perimeters of all almost equilateral triangles with integral side +lengths and area and whose perimeters do not exceed one billion (1,000,000,000). +""" + +def solution(max_perimeter: int = 10**9) -> int: + """ + Returns the sum of the perimeters of all almost equilateral triangles with integral + side lengths and area and whose perimeters do not exceed max_perimeter + + >>> solution(20) + 16 + """ + + prev_value = 1 + value = 2 + + sum = 0 + i = 0 + perimeter = 0 + while perimeter <= max_perimeter: + sum += perimeter + + prev_value += 2 * value + value += prev_value + + perimeter = 2 * value + 2 if i % 2 == 0 else 2 * value - 2 + + i += 1 + + return sum + + +if __name__ == "__main__": + print(f"{solution() = }") From e663843c190497c7218df2c2292c9b6890bef43e Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 1 Apr 2023 11:31:57 +0000 Subject: [PATCH 5/7] updating DIRECTORY.md --- DIRECTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 33c816fc4add..3ac902dda62c 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -937,6 +937,8 @@ * [Sol1](project_euler/problem_091/sol1.py) * Problem 092 * [Sol1](project_euler/problem_092/sol1.py) + * Problem 094 + * [Sol1](project_euler/problem_094/sol1.py) * Problem 097 * [Sol1](project_euler/problem_097/sol1.py) * Problem 099 From 206dbd960aaa63a78fe23cf7c858c74cd61dbda4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 1 Apr 2023 11:33:06 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- project_euler/problem_094/sol1.py | 1 + 1 file changed, 1 insertion(+) diff --git a/project_euler/problem_094/sol1.py b/project_euler/problem_094/sol1.py index c26df6f1848b..4ea299402a8e 100644 --- a/project_euler/problem_094/sol1.py +++ b/project_euler/problem_094/sol1.py @@ -12,6 +12,7 @@ lengths and area and whose perimeters do not exceed one billion (1,000,000,000). """ + def solution(max_perimeter: int = 10**9) -> int: """ Returns the sum of the perimeters of all almost equilateral triangles with integral From 3376a25c8be39a7505f7d9bb8b70911fd4f7eb72 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sat, 1 Apr 2023 14:34:57 +0300 Subject: [PATCH 7/7] Fix --- project_euler/problem_094/sol1.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/project_euler/problem_094/sol1.py b/project_euler/problem_094/sol1.py index 4ea299402a8e..a41292fe26fd 100644 --- a/project_euler/problem_094/sol1.py +++ b/project_euler/problem_094/sol1.py @@ -25,20 +25,19 @@ def solution(max_perimeter: int = 10**9) -> int: prev_value = 1 value = 2 - sum = 0 + perimeters_sum = 0 i = 0 perimeter = 0 while perimeter <= max_perimeter: - sum += perimeter + perimeters_sum += perimeter prev_value += 2 * value value += prev_value perimeter = 2 * value + 2 if i % 2 == 0 else 2 * value - 2 - i += 1 - return sum + return perimeters_sum if __name__ == "__main__":