Coding style improvements for project_euler problem 45 & 16 (#3087)

* improvements for project euler task 45

* fixed documentation

* update pe_16/sol1.py

* update pe_16/sol2.py

* revert solution changes for sol1

* revert solution changes for sol2

* remove trailing spaces in sol1

* Update sol1.py

Co-authored-by: Dhruv <dhruvmanila@gmail.com>
This commit is contained in:
fa1l 2020-10-09 11:39:44 +05:00 committed by GitHub
parent 216a194e9a
commit 10fe9d9be4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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, ...
@ -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
@ -54,4 +56,4 @@ def compute_num(start: int = 144) -> int:
if __name__ == "__main__":
print(f"{compute_num(144)} = ")
print(f"{solution()} = ")