Adopted new convention from template
This commit is contained in:
parent
e74454e4f5
commit
037fb1de95
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Created on 09 Sep 2021
|
||||
|
||||
@ -11,24 +11,28 @@ https://projecteuler.net/problem=45
|
||||
|
||||
from utils import timeit
|
||||
|
||||
|
||||
def pentagonal(n):
|
||||
return int(n * (3 * n - 1) / 2)
|
||||
|
||||
|
||||
def hexagonal(n):
|
||||
return int(n * (2 * n - 1))
|
||||
|
||||
|
||||
@timeit("Problem 45")
|
||||
def compute():
|
||||
"""
|
||||
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
|
||||
Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ...
|
||||
Pentagonal Pn=n(3n−1)/2 1, 5, 12, 22, 35, ...
|
||||
Hexagonal Hn=n(2n−1) 1, 6, 15, 28, 45, ...
|
||||
Pentagonal Pn=n(3n-1)/2 1, 5, 12, 22, 35, ...
|
||||
Hexagonal Hn=n(2n-1) 1, 6, 15, 28, 45, ...
|
||||
|
||||
It can be verified that T285 = P165 = H143 = 40755.
|
||||
|
||||
Find the next triangle number that is also pentagonal and hexagonal.
|
||||
"""
|
||||
|
||||
pentagonal_list = set(pentagonal(n) for n in range(2, 100_000))
|
||||
# all hexagonal numbers are also triangle numbers!
|
||||
hexagonal_list = set(hexagonal(n) for n in range(2, 100_000))
|
||||
@ -37,6 +41,6 @@ def compute():
|
||||
# First one is already known
|
||||
return ans[1]
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
print(f"Result for Problem 45: {compute()}")
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 45 is {compute()}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user