Skip to content

Commit f4c0a23

Browse files
committed
feat: add algorithm 95 to find the longest amicable chain
2 parents 021fefa + 89e57b6 commit f4c0a23

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

project_euler/problem_095/sol1.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
"""
22
Project Euler Problem: https://projecteuler.net/problem=95
33
4-
An amicable chain is a sequence of numbers where each number is the sum of the
5-
proper divisors of the previous one, and the chain eventually returns to the
6-
starting number. The problem is to find the smallest member of the longest
4+
An amicable chain is a sequence of numbers where each number is the sum of the
5+
proper divisors of the previous one, and the chain eventually returns to the
6+
starting number. The problem is to find the smallest member of the longest
77
amicable chain under a given limit.
88
9-
In this implementation, we aim to identify all amicable chains and find the
10-
one with the maximum length, while also returning the smallest member of that
9+
In this implementation, we aim to identify all amicable chains and find the
10+
one with the maximum length, while also returning the smallest member of that
1111
chain.
1212
"""
1313

14+
<<<<<<< HEAD
15+
=======
16+
17+
def sum_of_proper_divisors(number: int) -> int:
18+
"""Calculate the sum of proper divisors of the given number.
19+
>>>>>>> 89e57b63f62908f575161ca2c077f02c189a363c
1420
1521
def sum_of_proper_divisors(n):
1622
"""Calculate the sum of proper divisors of n."""
@@ -28,6 +34,12 @@ def sum_of_proper_divisors(n):
2834
2935
return total
3036
37+
<<<<<<< HEAD
38+
=======
39+
40+
def find_longest_amicable_chain(limit: int) -> int:
41+
"""Find the smallest member of the longest amicable chain under a given limit.
42+
>>>>>>> 89e57b63f62908f575161ca2c077f02c189a363c
3143

3244
def find_longest_amicable_chain(limit):
3345
"""Find the smallest member of the longest amicable chain under a given limit."""
@@ -66,6 +78,10 @@ def find_longest_amicable_chain(limit):
6678
return (
6779
min(longest_chain) if longest_chain else None
6880
) # Return the smallest member of the longest chain
81+
<<<<<<< HEAD
82+
=======
83+
84+
>>>>>>> 89e57b63f62908f575161ca2c077f02c189a363c
6985

7086

7187
def solution():

0 commit comments

Comments
 (0)