-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Changes from all commits
463b209
df4feca
0b376df
ff1005f
c2780f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: |
||
""" | ||
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! |
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(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file |
||
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()) |
There was a problem hiding this comment.
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 functioncalculate_energy_equivalent
Please provide type hint for the parameter:
mass