Skip to content

Added Project Euler - Problem 95 (Fixes #9166) #9193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions physics/einstein_mass_energy_equivalence_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Einstein's Energy-Mass Equivalence #9191 (https://github.com/TheAlgorithms/Python/issues/9191)

# https://www.github.com/JehanPatel

# What is Einstein's Energy-Mass Equivalence
# It expresses the fact that mass and energy are the same physical entity and can be changed into each other.
# Refer https://en.wikipedia.org/wiki/Mass%E2%80%93energy_equivalence for more information on the topic.

# Module for Einstein's Energy-Mass Equivalence.


def calculate_energy_equivalent(mass):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: calculate_energy_equivalent. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file physics/einstein_mass_energy_equivalence_module.py, please provide doctest for the function calculate_energy_equivalent

Please provide type hint for the parameter: mass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: calculate_energy_equivalent. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file physics/einstein_mass_energy_equivalence_module.py, please provide doctest for the function calculate_energy_equivalent

Please provide type hint for the parameter: mass

"""
Calculate the energy equivalent of a given mass.

:param mass: Mass in kilograms
:type mass: float
:return: Energy equivalent in joules
:rtype: float
"""
# Constants
G = 6.67430e-11 # Gravitational constant
c = 3.0e8 # Speed of light
h = 6.62607004e-34 # Planck constant

# Calculate energy equivalent
energy_equivalent = mass * c**2

return energy_equivalent


# Happy Coding!
46 changes: 46 additions & 0 deletions project_euler/problem_095/project_euler_095.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Project Euler - Problem 95
# Amicable Chains

# https://www.github.com/JehanPatel

# Refer to https://github.com/TheAlgorithms/Python/issues/9166 for further discussion on Project Euler - Problem 95

# What is Amicable Chains?
# Amicable chains are a sequence of numbers in which each number is the sum of the proper divisors of the number that follows it. For example, consider the sequence 220, 284, 220, 284, ... Here, 220 is the sum of the proper divisors of 284, and 284 is the sum of the proper divisors of 220.

# Problem Statement - https://user-images.githubusercontent.com/118645569/271806807-863546a0-c723-437a-9475-3017e3218d55.png

import itertools


def compute():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: compute. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file project_euler/problem_095/project_euler_095.py, please provide doctest for the function compute

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: compute. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file project_euler/problem_095/project_euler_095.py, please provide doctest for the function compute

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: compute. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file project_euler/problem_095/project_euler_095.py, please provide doctest for the function compute

LIMIT = 1000000

divisorsum = [0] * (LIMIT + 1)
for i in range(1, LIMIT + 1):
for j in range(i * 2, LIMIT + 1, i):
divisorsum[j] += i

maxchainlen = 0
ans = -1
for i in range(LIMIT + 1):
visited = set()
cur = i
for count in itertools.count(1):
visited.add(cur)
next = divisorsum[cur]
if next == i:
if count > maxchainlen:
ans = i
maxchainlen = count
break
elif next > LIMIT or next in visited:
break
else:
cur = next

return str(ans)


if __name__ == "__main__":
print(compute())