Skip to content

Commit 496cf48

Browse files
fa1ldhruvmanila
authored andcommitted
Coding style improvements for project_euler problem 45 & 16 (TheAlgorithms#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 <[email protected]>
1 parent 0d74d0b commit 496cf48

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Diff for: project_euler/problem_16/sol1.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""
2+
Problem 16: https://projecteuler.net/problem=16
3+
24
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
35
46
What is the sum of the digits of the number 2^1000?
57
"""
68

79

8-
def solution(power):
10+
def solution(power: int = 1000) -> int:
911
"""Returns the sum of the digits of the number 2^power.
1012
>>> solution(1000)
1113
1366

Diff for: project_euler/problem_16/sol2.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""
2+
Problem 16: https://projecteuler.net/problem=16
3+
24
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
35
46
What is the sum of the digits of the number 2^1000?
57
"""
68

79

8-
def solution(power):
10+
def solution(power: int = 1000) -> int:
911
"""Returns the sum of the digits of the number 2^power.
1012
1113
>>> solution(1000)

Diff for: project_euler/problem_45/sol1.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
Problem 45: https://projecteuler.net/problem=45
3+
24
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
35
Triangle T(n) = (n * (n + 1)) / 2 1, 3, 6, 10, 15, ...
46
Pentagonal P(n) = (n * (3 * n − 1)) / 2 1, 5, 12, 22, 35, ...
@@ -39,10 +41,10 @@ def is_pentagonal(n: int) -> bool:
3941
return ((1 + root) / 6) % 1 == 0
4042

4143

42-
def compute_num(start: int = 144) -> int:
44+
def solution(start: int = 144) -> int:
4345
"""
4446
Returns the next number which is traingular, pentagonal and hexagonal.
45-
>>> compute_num(144)
47+
>>> solution(144)
4648
1533776805
4749
"""
4850
n = start
@@ -54,4 +56,4 @@ def compute_num(start: int = 144) -> int:
5456

5557

5658
if __name__ == "__main__":
57-
print(f"{compute_num(144)} = ")
59+
print(f"{solution()} = ")

0 commit comments

Comments
 (0)