mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-19 19:03:02 +08:00
[Project Euler] Fix code style for multiple problems (#3094)
* Fix code style for Project Euler problems: - 13, 17, 21 - Default args - Type hints - File path * Fix code style for multiple problems * Made suggested changes
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
"""
|
||||
Problem 44: https://projecteuler.net/problem=44
|
||||
|
||||
Pentagonal numbers are generated by the formula, Pn=n(3n−1)/2. The first ten
|
||||
pentagonal numbers are:
|
||||
1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...
|
||||
@ -24,11 +26,11 @@ def is_pentagonal(n: int) -> bool:
|
||||
return ((1 + root) / 6) % 1 == 0
|
||||
|
||||
|
||||
def compute_num(limit: int = 5000) -> int:
|
||||
def solution(limit: int = 5000) -> int:
|
||||
"""
|
||||
Returns the minimum difference of two pentagonal numbers P1 and P2 such that
|
||||
P1 + P2 is pentagonal and P2 - P1 is pentagonal.
|
||||
>>> compute_num(5000)
|
||||
>>> solution(5000)
|
||||
5482660
|
||||
"""
|
||||
pentagonal_nums = [(i * (3 * i - 1)) // 2 for i in range(1, limit)]
|
||||
@ -42,4 +44,4 @@ def compute_num(limit: int = 5000) -> int:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"{compute_num() = }")
|
||||
print(f"{solution() = }")
|
||||
|
Reference in New Issue
Block a user