Skip to content
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

Hacktoberfest 2020 - coding style for project_euler problem 45 & 16 #3087

Merged
merged 8 commits into from
Oct 9, 2020
Merged
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
4 changes: 3 additions & 1 deletion project_euler/problem_16/sol1.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""
Problem 16: https://projecteuler.net/problem=16

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^1000?
"""


def solution(power):
def solution(power: int = 1000) -> int:
"""Returns the sum of the digits of the number 2^power.
>>> solution(1000)
1366
Expand Down
4 changes: 3 additions & 1 deletion project_euler/problem_16/sol2.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""
Problem 16: https://projecteuler.net/problem=16

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^1000?
"""


def solution(power):
def solution(power: int = 1000) -> int:
"""Returns the sum of the digits of the number 2^power.

>>> solution(1000)
Expand Down
8 changes: 5 additions & 3 deletions project_euler/problem_45/sol1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""
Problem 45: https://projecteuler.net/problem=45

Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
Triangle T(n) = (n * (n + 1)) / 2 1, 3, 6, 10, 15, ...
Pentagonal P(n) = (n * (3 * n − 1)) / 2 1, 5, 12, 22, 35, ...
Expand Down Expand Up @@ -39,10 +41,10 @@ def is_pentagonal(n: int) -> bool:
return ((1 + root) / 6) % 1 == 0


def compute_num(start: int = 144) -> int:
def solution(start: int = 144) -> int:
"""
Returns the next number which is traingular, pentagonal and hexagonal.
>>> compute_num(144)
>>> solution(144)
1533776805
"""
n = start
Expand All @@ -54,4 +56,4 @@ def compute_num(start: int = 144) -> int:


if __name__ == "__main__":
print(f"{compute_num(144)} = ")
print(f"{solution()} = ")